【发布时间】:2015-04-28 01:39:39
【问题描述】:
所需的货币格式如下所示
1,100,258
100,258
23,258
3,258
或所有整数,如
123456 或 2421323 等等。
我在下面输入ValidationExpression
(^[0-9]{1,3}(,\d{3})*) | (^[0-9][0-9]*)
但它不起作用。
【问题讨论】:
标签: asp.net regex validation webforms
所需的货币格式如下所示
1,100,258
100,258
23,258
3,258
或所有整数,如
123456 或 2421323 等等。
我在下面输入ValidationExpression
(^[0-9]{1,3}(,\d{3})*) | (^[0-9][0-9]*)
但它不起作用。
【问题讨论】:
标签: asp.net regex validation webforms
你有ignore pattern whitespace 吗?如果没有,请删除管道两侧的两个空格。
由于您尝试匹配任何一个,因此您应该在字符串末尾添加一个标记 $,就像这样
还有^[0-9][0-9]*有什么意义,什么时候可以用^[0-9]+?
^([0-9]{1,3}(?:,\d{3})*|[0-9]+)$
或
^(\d{1,3}(?:,\d{3})*|\d+)$
解释:
^ # Anchors to the beginning to the string.
( # Opens CG1
\d{1,3} # Token: \d (digit)
(?: # Opens NCG
, # Literal ,
\d{3} # Token: \d (digit)
# Repeats 3 times.
)* # Closes NCG
# * repeats zero or more times
| # Alternation (CG1)
\d+ # Token: \d (digit)
# + repeats one or more times
) # Closes CG1
$ # Anchors to the end to the string.
【讨论】: