I'm in trouble: i need a regex that match this
VALID:
3
44
55.5
66.66
777
NOT VALID:
3,3
.4
.55
-7
The regex must validate only unsigned integer or float, only dot (not comma), max 2 decimal.
You could try the below,
^[0-9]+(?:\.[0-9]{1,2})?$
^ Asserts that we are at the start. $ asserts that we are at the end. Basically anchors are used to do an exact string match. \d{1,2} matches one or two digits.
DEMO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With