libphonenumber\PhoneNumberUtil::convertAlphaCharactersInNumber PHP Method

convertAlphaCharactersInNumber() public static method

Converts all alpha characters in a number to their respective digits on a keypad, but retains existing formatting.
public static convertAlphaCharactersInNumber ( string $number ) : string
$number string
return string
    public static function convertAlphaCharactersInNumber($number)
    {
        if (static::$ALPHA_PHONE_MAPPINGS === null) {
            static::initAlphaPhoneMappings();
        }
        return static::normalizeHelper($number, static::$ALPHA_PHONE_MAPPINGS, false);
    }

Usage Example

 public function testConvertAlphaCharactersInNumber()
 {
     $input = "1800-ABC-DEF";
     // Alpha chars are converted to digits; everything else is left untouched.
     $expectedOutput = "1800-222-333";
     $this->assertEquals($expectedOutput, $this->phoneUtil->convertAlphaCharactersInNumber($input));
 }
PhoneNumberUtil