Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Number validate regex

From jquery.validate.js, this regex is used to validate a number. The problem is that it fails on .33 and passes on 0.33. I need to make it pass with, or without, the leading 0.

^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$
like image 930
Darthg8r Avatar asked May 06 '26 23:05

Darthg8r


1 Answers

Try this

^-?(?:\d+|\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$

The extra question mark (spot it!) will make all the part before the decimal point optional.

like image 95
solendil Avatar answered May 08 '26 13:05

solendil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!