I am using the following regex to validate decimal numbers with dot .
/^[0-9]*\.?[0-9]*$/
It works fine for all the cases except the case 12.
Working Example:
12
12.2
10.222
12.
I want to throw validation error when user enters (12.): at least a digit after decimal point needs to be entered (like 12.1).
You can use this regex:
/^\d+(\.\d+)?$/
It will match whole number: 12, 1222
If there is a decimal point, then there must be at least 1 digit before and after the decimal point: 1.1, 34.2
These cases are not allowed: .43, 23.
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