Regular expression for 10 digit number without any special characters

前端 未结 5 757
轻奢々
轻奢々 2020-12-06 03:44

What is the regular expression for a 10 digit numeric number (no special characters and no decimal).

5条回答
  •  鱼传尺愫
    2020-12-06 04:24

    Use this regular expression to match ten digits only:

    @"^\d{10}$"
    

    To find a sequence of ten consecutive digits anywhere in a string, use:

    @"\d{10}"
    

    Note that this will also find the first 10 digits of an 11 digit number. To search anywhere in the string for exactly 10 consecutive digits and not more you can use negative lookarounds:

    @"(?

提交回复
热议问题