What would be asp .net regular expression for allowing negative & positive number except 0 with only up-to 2 decimal places? It should not allow more than 2 digits after decimal. So allowed would be
1
72.25
568
7898578
-1
-3233443
0.01
-0.14
Disallowed
0
1.235
-5.658
0.0
0.00
>Solution :
Try:
https://regex101.com/r/tbdE5Q/latest
^(?!0+(\.0+)?)-?\d+(?:\.\d{1,2})?$
Explaination
^ anchors start of string
(?! ensures that the match is not …
0+ constituted of only 0
(\.0+)? and optionally a decimal point . followed by only 0s
) ends 0 case
-? allows - sign
\d+ any number of digits before decimal point
(?: optional non-capture group
\. decimal point …
\d{1,2} and up to two digits
)? end optional non-capturing group
$ anchors end of string