问题描述
我 ValidationRegularEx pression =[0-9]
只允许单个字符。我如何使它允许之间(包含),1和7位数?我试图 [0-9] {1-7}
,但没有奏效。
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]{1-7}
but it didn't work.
推荐答案
您得到了语法正确的差不多: [0-9] {1,7}
You got the syntax almost correct: [0-9]{1,7}
.
您可以让您的解决方案有点更优雅(文化敏感),用 [0-9]
与通用字符组十进制数字: \\ D
(记住,其它语言可能比0-9使用不同的字符位数)。
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
这篇关于简单的整数定期EX pression的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!