简体   繁体   中英

country code validation with + symbol, Android

In my application users enters mobile number's country code with '+' symbol. Right now I am checking for + symbol. If they enter '+INDIA', according to my code this is correct. But according to logic this is wrong. They needs to enter '+91'. Means they can enter only 1, 2 or 3 digit number with '+' symbol. for example '+1', '+91' or '+234'. How I can achieve this type of validation in android?

You could write your own Pattern to check the format. I could give you the example, but I think the site I linked explains it much better.

It should probably start with something like \\+\\d\\d?\\d?

You could try using Google's own implementation of Phone Numbers or this xml list .

Hope it helps !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM