Extract the country code information from an ordinary phone number
- The length of the phone number isn't important.
- The number doesn't have to obey the belonging country's rules. The country prefix is enough.
(no other initialization or sth needed other than this: )
System.out.println(CountryCodeMatcher.getCountry("12355555").getName());
will print out:
US/CA
or, this
System.out.println(CountryCodeMatcher.getCountry("72355555").getName());
KZ/RU
These are ridiculous numbers and their output when tried.
812355555 > JP
99611111 > KG
90212545455 > TR
9761515151 > MN
44148112131 > GG
...
The project doesn't contain information for cities. But, you can use it if you have the data already. For instance:
System.out.println(CityCodeMatcher.getCity("9021233333333333").getName());
System.out.println(CityCodeMatcher.getCity("9021633333333333").getName());
would give
Istanbul (Europe)
Istanbul (Asia)
If you have prefices for cities or data alike, you can edit com.dkavraal.countrycode.data.CityDataContainer There are already samples in the file.