Validation in Mobile number

Asked by At

Its Validation in Android : User will use these mobile format case in EditText box at login time Note : country code will be any . 1. Only contact no. , like : 7042955698 2. 0 + contact no. , like 0 7042955698 3. Country code + contact no. , Like 91 7042955698 4."+" + Country code + contact no. , Like +91 7042955698 5. 00 + country code + contact no. , like 00 91 7042955698 From this we should get only contact no. How can be solve this problem? Thanks in Advance!! cheers

1 Answers

0
Viraj S On

please try in these two ways,
1. Use a device default phone matching pattern to check the number validation in if-else like,

android.util.Patterns.PHONE.matcher(editText.getText().toString()).matches()

2. Create your own pattern for mobile number and validate using if-else. (pattern should be in a string format to compare) like

if (editText.getText().toString().matches(your_contact_Pattern))

Hope it helps logically.