Monday, 23 September 2019

Regular expression in c# - 7 digits with 2 decimal places


Regular expression  in c# - 7 digits with 2 decimal places
eg: 1234567.12
or 123.12
or 123
or 123.11


^-?(0|[1-9]\d{0,6})([,\.]\d{1,2})?$


BEFORE COMMA:

^ - beginning of the string

-? - there may be zero or one negative sign

0 - decimal may starts with only single zero at the beginning...

| - or ...

[1-9] - with any digit from 1 to 9

\d{0,6} - followed by any 7 digits

AFTER COMMA:

[,.] - there may be "," or "."

\d{1,2} - followed by 1 or 2 digits

(...)? - zero or one time

$ - end of the string

No comments:

Post a Comment