iftekhs's avatar
Level 13

libphonenumber\PhoneNumberUtil cannot validate a US number

Hi, I'm using the libphonenumber\PhoneNumberUtil package to validate a US number which is "1555700XXXX" but it is giving me the following error

$number = "1555700XXXX";
$phoneUtil = PhoneNumberUtil::getInstance();
$numberProto = $phoneUtil->parse($number, null);
return $phoneUtil->isValidNumber($numberProto);

error
------------------
Missing or invalid default region.
0 likes
2 replies
MohamedTammam's avatar

Change it to this

$numberProto = $phoneUtil->parse($number, 'US');
1 like
iftekhs's avatar
Level 13

@MohamedTammam Tried it still the same thing I found the issue to be the "555" prefix which I think is detected as a non-standard number that is just for testing or something

Please or to participate in this conversation.