This method does not require the number to be normalized in advance - but does assume that
leading non-number symbols have been removed, such as by the method extractPossibleNumber.
public static isViablePhoneNumber ( string $number ) : boolean | ||
$number | string | to be checked for viability as a phone number |
return | boolean | true if the number could be a phone number of some sort, otherwise false |
public function testIsViablePhoneNumberNonAscii() { // Only one or two digits before possible punctuation followed by more digits. $this->assertTrue(PhoneNumberUtil::isViablePhoneNumber("1" . pack('H*', 'e38080') . "34")); $this->assertFalse(PhoneNumberUtil::isViablePhoneNumber("1" . pack('H*', 'e38080') . "3+4")); // Unicode variants of possible starting character and other allowed punctuation/digits. $this->assertTrue(PhoneNumberUtil::isViablePhoneNumber(pack('H*', 'efbc88') . "1" . pack("H*", 'efbc89') . pack('H*', 'e38080') . "3456789")); // Testing a leading + is okay. $this->assertTrue(PhoneNumberUtil::isViablePhoneNumber("+1" . pack("H*", 'efbc89') . pack('H*', 'e38080') . "3456789")); }