I want to validate phone number.
Phone Number = countryCode+areaCode+PhoneNumber
.
I want to know what is the standard minimum and maximum length of Phone Number so i could validate it.
-thanks
Asked
Active
Viewed 208 times
0

Usman Riaz
- 2,920
- 10
- 43
- 66
-
2That actually depends on the country, so it's not a simple problem. – EpicPandaForce Feb 04 '15 at 13:50
-
so what to do? any solution? thanks – Usman Riaz Feb 04 '15 at 13:50
-
You probably need something like https://github.com/googlei18n/libphonenumber – EpicPandaForce Feb 04 '15 at 13:57
2 Answers
0
Try this regex:
^[+]?[0-9]{10,13}$
Or this:
PhoneNumberUtils.isGlobalPhoneNumber("+912012185234");

GIGAMOLE
- 1,274
- 1
- 11
- 17
0
It would depend on if you are accepting any country code or are looking for specific country code/s.
Then how many digits you are expecting for area code and then the actual phone number and whether these are being fetched as separate variables or one string.
So after answering these question. You can use (test your code) regex (learn how to use it), (and as @Basil has suggested), but vary the length (and possibly digits, if there are limited country codes) accordingly.
Here is a good answer to using regex in android.

Community
- 1
- 1