Announcement

Collapse
No announcement yet.

Automatically Remove Special Characters in phone number.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • telecastg
    commented on 's reply
    You're welcome :-)

  • ciryaj
    replied
    Originally posted by telecastg View Post
    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;
    }
    got it working. THANKS for leading me to it.

    Leave a comment:


  • telecastg
    replied
    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;
                }

    Leave a comment:


  • ciryaj
    replied
    Originally posted by telecastg View Post
    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);
        }
    
    }
    
    ?>

    Leave a comment:


  • telecastg
    replied
    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);

    Leave a comment:


  • Automatically Remove Special Characters in phone number.

    How can we make the Phone number stored with no special character. Through this it can be searched easily.
Working...
X