Email and phone Number Validation in android

后端 未结 12 1251
青春惊慌失措
青春惊慌失措 2020-12-02 11:03

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.<

12条回答
  •  攒了一身酷
    2020-12-02 11:44

    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.

提交回复
热议问题