Flutter - Validate a phone number using Regex

后端 未结 2 826
旧时难觅i
旧时难觅i 2021-01-31 19:23

In my futter mobile app, I am trying to validate a phone number using regex. Below are the conditions.

  1. Phone numbers must contain 10 digits.
2条回答
  •  轮回少年
    2021-01-31 19:35

    You could make the first part optional matching either a + or 0 followed by a 9. Then match 10 digits:

    ^(?:[+0]9)?[0-9]{10}$
    
    • ^ Start of string
    • (?:[+0]9)? Optionally match a + or 0 followed by 9
    • [0-9]{10} Match 10 digits
    • $ End of string

    Regex demo

提交回复
热议问题