Regex to only allow numbers under 10 digits?

前端 未结 7 1759
暖寄归人
暖寄归人 2020-12-16 22:06

I\'m trying to write a regex to verify that an input is a pure, positive whole number (up to 10 digits, but I\'m applying that logic elsewhere).

Right now, this is t

7条回答
  •  悲&欢浪女
    2020-12-16 22:12

    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.

    @"(?

提交回复
热议问题