简体   繁体   English

数字格式的javascript正则表达式

[英]javascript regular expression for number format

Can you suggest a javascript regex to check the number format 1.00.999,000 你能建议一个javascript正则表达式检查数字格式1.00.999,000
here '.' 这里 '。' represents 100's and ',' represents decimal points. 代表100和','代表小数点。

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} 1.00.999,000变为[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 . 所以two numbers ,后跟任意数量的dot three number后跟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. 我在解释数字格式时可能会出错,但我怀疑你的1.00.999,000的例子在左边的第一个分组(000而不是00)中应该有一个额外的零,以使其与样本一致,或者删除点介于1.00之间。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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