libphonenumber\PhoneNumberUtil::normalizeDiallableCharsOnly PHP Метод

normalizeDiallableCharsOnly() публичный статический Метод

Normalizes a string of characters representing a phone number. This strips all characters which are not diallable on a mobile phone keypad (including all non-ASCII digits).
public static normalizeDiallableCharsOnly ( string $number ) : string
$number string a string of characters representing a phone number
Результат string the normalized string version of the phone number
    public static function normalizeDiallableCharsOnly($number)
    {
        if (count(static::$DIALLABLE_CHAR_MAPPINGS) === 0) {
            static::initDiallableCharMappings();
        }
        return static::normalizeHelper($number, static::$DIALLABLE_CHAR_MAPPINGS, true);
    }

Usage Example

 public function testNormaliseStripNonDiallableCharacters()
 {
     $inputNumber = "03*4-56&+a#234";
     $expectedOutput = "03*456+234";
     $this->assertEquals($expectedOutput, $this->phoneUtil->normalizeDiallableCharsOnly($inputNumber), "Conversion did not correctly remove non-diallable characters");
 }
PhoneNumberUtil