3

I have contact like "+919672525253".Now i extract the country code like "91" from that number.Now if number is like "9672525253" and if i extract the country code then it will give me "967".So after extracting the country code how can i check that remaining number is valid mobile number for that country code or not? EDIT

If any body know the mobile number length country wise then also i can solve this problem.like in india 10 digits.

jugni
  • 113
  • 1
  • 13

2 Answers2

3

You pretty much can't. For example in the US mobile numbers and landline numbers are indistinguishable, they have normal area codes just like landline numbers. Even if it were possible every country does it differently and it is also constantly changing as numbers run out new prefixes are added and things change and their is no pattern you could match against or database you could do a lookup against.

Ben Robinson
  • 21,601
  • 5
  • 62
  • 79
1

Take a look at libPhoneNumber (bundled in ICS) which can help validating a phone number (see PhoneNumberUtils). There's a MobileType you can get after validation but as stated in the source and by Ben, in some region this will not work.


EDIT:

Some validation code (here we need to check the phone is a valid one assuming it's a french one):

boolean isValid = false;
PhoneNumber number = null;
try {
    number = this.phoneUtil.parse(phone, "FR"); // phone is number in internationnal format "+xxxxxx"
    isValid = this.phoneUtil.isValidNumber(number);
} catch (final NumberParseException e) {
    // ...
}

isValid // is the phone number valid according to the library?
this.phoneUtil.getRegionCodeForNumber(number); // this gets the country code of the phone as found by the library (for example "US", "CH", "GB", ...)

This works for us but you'll need to try it to see if it suit your need.