Simple integer regular expression

后端 未结 2 1185
醉酒成梦
醉酒成梦 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:22

    You got the syntax almost correct: [0-9]{1,7}.

    You can make your solution a bit more elegant (and culture-sensitive) by replacing [0-9] with the generic character group "decimal digit": \d (remember that other languages might use different characters for digits than 0-9).

    And here's the documentation for future reference:

    • .NET Framework Regular Expressions

提交回复
热议问题