I can get contact number from phone. I want to know how to remove the country code from it. That is if user has the phone number with country code(+91-9876543210), i need the phone number without prefixed country code(9876543210).
Thanks in advance.
I'd suggest to use libphonenumber to parse the phone numbers easily. You can split the country code and phone number in this way.
try {
// phone must begin with '+'
PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
Phonenumber.PhoneNumber numberProto = phoneUtil.parse("+91-9876543210", "");
int countryCode = numberProto.getCountryCode();
long nationalNumber = numberProto.getNationalNumber();
Log.i("code", "code " + countryCode);
Log.i("code", "national number " + nationalNumber);
} 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