问题描述
我有 ASP:文本框
来保持价值的钱,也就是'1000','1000,0'和'1000,00'(逗号分隔符,因为俄罗斯标准)。
什么 ValidationEx pression
有我使用到合适 ASP:RegularEx pressionValidator
我试过 \ D + \,\ D {0,2}
,但它并没有让一些不带小数点的数字,例如:只是'1000'。
\ D +(,\ D {1,2})?
将只允许当你有小数位的逗号,并允许没有逗号的。问号的意思是一样 {0,1}
,所以在 \ D +
你要么零实例(即没有)或者一个实例
,\ D {1,2}
由于海伦正确地指出,就足以证明了使用非捕获组,如
\ D +(?,\ D {1,2})?
附加:
意味着括号只是为了小组,\ D {1,2}
部分,用于由问号使用,但也没有必要记住什么被这些括号内匹配。因为这意味着正则表达式ENGINGE更少的工作,你就会得到性能的提升。
I have asp:TextBox
to keep a value of money, i.e. '1000', '1000,0' and '1000,00' (comma is the delimiter because of Russian standard).
What ValidationExpression
have I to use into appropriate asp:RegularExpressionValidator
?
I tried \d+\,\d{0,2}
but it doesn't allows a number without decimal digits, e.g. just '1000'.
\d+(,\d{1,2})?
will allow the comma only when you have decimal digits, and allow no comma at all. The question mark means the same as {0,1}
, so after the \d+
you have either zero instances (i.e. nothing) or one instance of
,\d{1,2}
As Helen points out correctly, it will suffice to use a non-capturing group, as in
\d+(?:,\d{1,2})?
The additional ?:
means that the parentheses are only meant to group the ,\d{1,2}
part for use by the question mark, but that there is no need to remember what was matched within these parenthesis. Since this means less work for the regex enginge, you get a performance boost.
这篇关于正则表达式钱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!