Reputation: 837
I require a regex to validate fixed range decimal numbers e.g. 1234.1234 - valid, 4444.1234 - valid 123.123 - invalid, 1234.123 - invalid
The number 4 digit before decimal and 4 digit after decimal only valid.
I'm currently uses this regex - /^\S((\d{4})((\.\d{4})?))$/
but this not satisfies me.
Upvotes: 1
Views: 596
Reputation: 67968
^\d{4}(\.\d{4})?$
This should do it for you.Use
^[1-9]\d{3}(\.\d{4})?$
If you dont want to match 0234.1234
Upvotes: 2
Reputation: 784998
You can use this regex:
/^\d{4}(?:\.\d{4})?$/
This will match 1234
or 1234.5678
as valid matched.
Upvotes: 0