开发者

Why "\d+{1,4}(?:[.,]\d{1,4})?" in RegularExpressionValidator throws Exception: "Nested quantifier {"

开发者 https://www.devze.com 2022-12-29 03:49 出处:网络
I have <asp:RegularExpressionValidator ValidationExpression="\\d+{1,4}(?:[.,]\\d{1,4})?" />

I have

<asp:RegularExpressionValidator ValidationExpression="\d+{1,4}(?:[.,]\d{1,4})?" />

but it doesn't' work, parser throws ArgumentException:

parsing "\d+{1,4}(?:[.,]\d{1,4})?"

Nested quantifier {.

Where is my mistake? I want to allow strings like xxxx,xxxx - from 1 to 4 digits and decimal digits are not required, e.g.: 1000, 99,99, 0,249开发者_运维知识库8, etc.


This looks wrong:

\d+{1,4}

Should be this:

\d{1,4}

The + means 'one or more' and the {1,4} means between one and four. They cannot be used together as it would not make sense.


I think this should do it:

\d{1,4}(?:,\d{1,4})?


I think you want

[.,]?

Instead of

?:[.,]
0

精彩评论

暂无评论...
验证码 换一张
取 消