Simple integer regular expression

后端 未结 2 1224
醉酒成梦
醉酒成梦 2021-02-20 08:48

I have ValidationRegularExpression=\"[0-9]\" which only allows a single character. How do I make it allow between (and including) 1 and 7 digits? I tried [0-9

2条回答
  •  迷失自我
    2021-02-20 09:31

    If you want to avoid leading zeros, you can use this:

    ^(?!0\d)\d{1,7}$
    

    The first part is a negative lookahead assertion, that checks if there is a 0 followed by a number in the string. If so no match.

    Check online here: http://regexr.com?2thtr

提交回复
热议问题