Listing all country codes of phone numbers

ann picture ann · May 29, 2013 · Viewed 35k times · Source

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?

Answer

Ram picture Ram · Oct 29, 2014

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.

Set<String> set = PhoneNumberUtil.getInstance().getSupportedRegions();

String[] arr = set.toArray(new String[set.size()]);

for (int i = 0; i < arr.size(); i++) {
    Locale locale = new Locale("en", arr[i]);
    Log.d(TAG, "lib country:" + arr[i] + "  "+ locale.getDisplayCountry());
}