简体   繁体   中英

javascript regular expression for number format

Can you suggest a javascript regex to check the number format 1.00.999,000
here '.' represents 100's and ',' represents decimal points.

If your just asking for a number format for your exact match then

1.00.999,000 becomes [0-9]\\.[0-9]{2}.[0-9]{3},[0-9]{3}

What I suspect you really want may be

[0-9]{0,2}(.[0-9]{3})+,[0-9]{0,3}

so two numbers , followed by any amount of dot three number followed by , between 0 and 3 numbers . I could be wrong in interpreting the number format but I suspect your example of 1.00.999,000 should have an extra zero in the first grouping from the left (000 instead of 00) to make it uniform with the sample after it, or drop the dot between the 1.00.

这适用于带或不带小数的数字(最多3个)

[0-9]{1,2}(\.[0-9]{3})*(,[0-9]{1,3})?

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