I have a registration form in my application which I am trying to validate. I\'m facing some problems with my validation while validating the phone number and email fields.<
He want an elegant and proper solution try this small regex pattern matcher.
This is specifically for India.(First digit can't be zero and and then can be any 9 digits)
return mobile.matches("[1-9][0-9]{9}");
Pattern Breakdown:-
[1-9]
matches first digit and checks if number(integer) lies between(inclusive) 1 to 9
[0-9]{9}
matches the same thing but {9}
tells the pattern that it has to check for upcoming all 9 digits.
Now the {9} part may vary for different countries so you may have array which tells the number of digits allowed in phone number. Some countries also have significance for zero ahead of number, so you may have exception for those and design a separate regex patterns for those countries phone numbers.