I try to use the libphonenumber library to parse a string that contains a phone number but is prefixed with zero before the international country code, but I get an exception:
"INVALID_COUNTRY_CODE. Could not interpret numbers after plus-sign."
and how can I make it work only for two zero characters before the country code or after the country code, but should fail if it has more than 2 zero characters.
Prefix 00
is not the "official" prefix for country codes in all countries. Therefore, the library does not accept it by default.
You can test the library on this page: https://www.php.cn/link/69bfa2aa2b7b139ff581a806abf0a886
When you select the default country that uses 00
as the country code prefix, you will see that only your number is accepted. You can test this by setting gb
in the Default Country field.
You can visit this page
As you can see, the second parameter of the parse
method is defaultRegion. You must set a country that uses the phone number format you want to parse.
This answers the second part of your question. As you will see the first part of the question has the same solution.
The above is the detailed content of Googlecode libphonenumber in Java, how to parse PhoneNumber string '0044********' or '044********' where 44 is the country code but prefixed with zero. For more information, please follow other related articles on the PHP Chinese website!