Home > Java > body text

Googlecode libphonenumber in Java, how to parse PhoneNumber string '0044********' or '044********' where 44 is the country code but prefixed with zero

WBOY
Release: 2024-02-06 08:24:03
forward
678 people have browsed it
Question content

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."
Copy after login

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.


Correct answer


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: //m.sbmmt.com/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!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template