Regex to check number starts with '078'

后端 未结 2 1201
说谎
说谎 2021-01-25 15:52

I need to validate a Textbox in my Asp.Net application where the user can enter mobile number and it should starts with 078 and should contain 10 digits.

Sample:

相关标签:
2条回答
  • 2021-01-25 16:32

    Why don't you try this? The below regex would validate for phone numbers which should be starts with 078 followed by any 7 digit number.

    ^078\d{7}$
    

    DEMO

    Explanation:

    • ^ Asserts that we are at the start.
    • 078 Matches exactly the digits 078.
    • \d{7} Matches the following 7 digits.
    • $ End of the line.

    IDEONE

    0 讨论(0)
  • 2021-01-25 16:43
    ^078[0-9]{7}$
    

    This is a bit faster than \d if we use only numbers here.

    0 讨论(0)
提交回复
热议问题