I have written a Regex which will take only integers but I need to rewrite this regex to only allow 3 digit before precision and 2 digits after precision
How to do that?
I have written a Regex which will take only integers but I need to rewrite this regex to only allow 3 digit before precision and 2 digits after precision
How to do that?
Share Improve this question edited Oct 24, 2012 at 10:33 Lee Taylor 7,99416 gold badges37 silver badges53 bronze badges asked Oct 24, 2012 at 10:27 PeteEngineerPeteEngineer 1134 silver badges14 bronze badges 02 Answers
Reset to default 8If it must always have 3 digits, a decimal point, and 2 digits, e.g., 412.88
, then:
/^\d{3}\.\d{2}$/
If it can be up to 3 digits before and up to 2 after (possibly no decimal point at all) then maybe something like:
/^\d{1,3}(\.\d{1,2})?$/
In c#
@"^\d{3}\.\d{2}$"
//in c# we need to use verbatim string `@""` to treat escape sequences as normal literals instead of giving it a special meaning..
In javascript
/^\d{3}\.\d{2}$/