正则表达式数量验证

男孩3

我想在以下情况下验证金额。下面的正则表达式可以正常工作,除了“,”,例如1,000.0000

^(?!0*(\.0+)?$)(\d*(?:\.[0-9]{0,4})?)$

1 - should pass
0.1 - should pass
.1 - should pass
0 - should fail
.0001 - should pass
.10 - should pass
0.0  - should fail
0.00000 - should fail (only accept 4 digits after the decimal point)
1.0000 - should pass
1,000.0000 - should pass
1,000,00.000 - should pass
1,000.0000 - should pass
亚历山大·马辛

^(?![0,]*(\.0+)?$)([,\d]*(?:\.[0-9]{0,4})?)$我只是\d将小数点分隔符前的[,\d];替换为; 并且在否定断言中也是如此0,000.00它允许在各处放置任意数量的逗号,这是合理的,因为本地数字分组传统不同。

另外,您是否想要带有悬挂点的数字10.来匹配?如果不是,请替换{0,4}{1,4}https://regex101.com/r/XB8OtL/3

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章