I'd like to have the country code list for phone numbers. Such as, United State (+1), United Kingdom (+44) ... I know that libphonenumber is a great tool to help phone parsing, formatting and validation. However, it doesn't seem to have the functionality for listing all country codes. But those data should be within the metadata in libphonenumber, right? Does anyone have experience on this?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
I generated json file with all country codes in the following format:
I am an android developer. I am using the libphonenumber library along with java.util.Locale class to complete this as follows. It may be late response, but hope it helps someone like me in future.
Phonelibnumber HAS built-in method which returns a Set of supported country codes.
Just call
phoneNumberUtil.getSupportedCallingCodes()
.(for instance, it will return you 1 for the US and 380 for Ukraine).
Then if you need you can iterate over them and get the region code:
It will return you US and UA for the mentioned above countries.
If you need the country name - retrieve it from locale:
That will give you
United States
andUkraine
accordinglyYou can call
PhoneNumberUtil.getSupportedRegions()
. This will return an array of country codes ordered alphabetically.Here is a resource with country codes, country names, etc.
Note that
phoneUtil.getCountryCodeForRegion
returns "1" for North American Numbering Plan countries such as Barbados, which is incorrect.Use the
getSupportedRegions()
method, then iterate these regions callinggetCountryCodeForRegion()
.