How can we make the Phone number stored with no special character. Through this it can be searched easily.
Automatically Remove Special Characters in phone number.
Collapse
X
-
Actually espo saves phone numbers as entered and also in numeric format only in the database table phone_number.
If you wish to store a phone number in numeric format only for a custom entity, you can create a beforeSave hook for that entity and include this statement:
Code:$numericPhone = preg_replace('/[^0-9]/', '', $formattedPhoneNumber);
-
Actually espo saves phone numbers as entered and also in numeric format only in the database table phone_number.
If you wish to store a phone number in numeric format only for a custom entity, you can create a beforeSave hook for that entity and include this statement:
Code:$numericPhone = preg_replace('/[^0-9]/', '', $formattedPhoneNumber);
It didn't work. This is the code
Code:<?php namespace Espo\Custom\Entities; use Espo\ORM\Entity; class entest extends \Espo\Core\Templates\Entities\Base { // protected $entityType = "entest"; public function beforeSave(Entity $entity, array $options = []) { $phonenum = preg_replace("/[^0-9]/", "", $phonenum); } } ?>
Comment
-
You need to define the formatted number variable first and then define a NEW variable which will store the "clean" number. In your script you are defining "$phonenum" as a modified string of "$phonenum" which doesn't exist yet.
See the script: application/Espo/Repositories/PhoneNumber.php
Code:$number = $entity->get('name'); if (is_string($number) && strpos($number, self::ERASED_PREFIX) !== 0) { $numeric = preg_replace('/[^0-9]/', '', $number); } else { $numeric = null; }
Comment
-
You need to define the formatted number variable first and then define a NEW variable which will store the "clean" number. In your script you are defining "$phonenum" as a modified string of "$phonenum" which doesn't exist yet.
See the script: application/Espo/Repositories/PhoneNumber.php
Code:$number = $entity->get('name'); if (is_string($number) && strpos($number, self::ERASED_PREFIX) !== 0) { $numeric = preg_replace('/[^0-9]/', '', $number); } else { $numeric = null; }
Comment
Comment