views:

86

answers:

3

I have asp:RegularExpressionValidator with 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,2498, etc.

A: 

I think you want

[.,]?

Instead of

?:[.,]
Adam Robinson
I need to make whole right part to be optional, as far as I understand your code makes only `[.,]` to be optional.
abatishchev
The whole right part was already optional because of your trailing `?`
Adam Robinson
+2  A: 

I think this should do it:

\d{1,4}(?:,\d{1,4})?
Deniz Dogan
+5  A: 

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.

Mark Byers