I need a regex in PHP to only allow only 2 decimal places to the right of the decimal and no digits on the left side of the decimal. What I have so far allows digits to the left side of the decimal point.
/^\.[0-9]{1,2}$/
Thanks in advance.
Allowed
.01
.40
.99
Not Allowed
1.01
5.50
1.99
/^[.]{1}[0-9]{2}$/
That regex matches the character "." 1 time and any number after, exactly two times. If the string is not in the format .01 or .23 and so forth, it wont accept it
Assuming you want exactly two digits after the decimal: /^\.\d{2}$/
Assuming you want one or two digits after the decimal: /^\.\d{1,2}$/