I have a list of mobile numbers with country code like "919638095998"number. I have referred the libphonenumber google example also but in that first we need to pass the country 2 digit code, which I don't know initially. So how can I know that the number is from which country?
I have also got one solution as manually extract the code one by one digit from mobile number and then compare with country code. But it is a long task and also it will give me bad performance. Can anyone suggest a proper solution?
libphonenumber does that for you. All you have to do is add the + sign before your phone number and omit the country code when parsing the phone number. Show activity on this post.
All you have to do is add the + sign before your phone number and omit the country code when parsing the phone number. Show activity on this post. There is a list of all the phone numbers available for country codes on Wikipedia.
Extract Phone Numbers Phone Extractor For Web Pages and Text Use this tool to find and extract Phone numbers in web pages, data files, ... What can this tool do? Use this tool to extract Phone numbers from web pages and data files.
In react native we can use React Native Phone Number Input NPM and YARN package to add country code input picker in our app. So in this tutorial we would learn about Example of React Native Phone Number Input Get Country Code.
libphonenumber does that for you. All you have to do is add the +
sign before your phone number and omit the country code when parsing the phone number.
String numberStr = "+919638095998";
PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
try {
Phonenumber.PhoneNumber numberProto = phoneUtil.parse(numberStr, "");
System.out.println("Country code: " + numberProto.getCountryCode());
//This prints "Country code: 91"
} catch (NumberParseException e) {
System.err.println("NumberParseException was thrown: " + e.toString());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With