简体   繁体   中英

Regex Javascript Numbers Comma Separated | > | >= <=

I'm using this Regex to validate numbers with decimals (comma separated)

/(^\d*\,?\d*[1-9]+\d*$)|(^[1-9]+\d*\,\d*$)/

but i need to change it so that it can also validate numbers higher than 5000 and between 3000 and 1000000

I'm not a Regex expert even though i have read several tutorials i'm still unable to find a solution...any help is appreciated. thanks in advance.

This will match numbers between 3000 and 1000000, inclusive, allowing an optional fractional part separated by a coma:

 /^([3-9][0-9]{3}(,[0-9]+)?|[1-9][0-9]{4,5}(,[0-9]+)?|1000000)$/

You can test it here .

This will match numbers greater or equal to 5000, allowing an optional fractional part separated by a coma:

 /^([5-9][0-9]{3}|[1-9][0-9]{4,})(,[0-9]+)?$/

You can test it here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM