[英]Regex for dollar currency format
I need a regex to check if the value is valid dollar currency我需要一个正则表达式来检查该值是否是有效的美元货币
eg 12,123,212.00例如 12,123,212.00
You can try this...你可以试试这个...
^\$?((\d{1,3})(?:,[0-9]{3}){0,1}|(\d{1})(?:,[0-9]{3}){0,2}|(\d{1,7}))(\.\d{1,2})?$
If you really want to use regex to validate your input then you may consider:如果您真的想使用正则表达式来验证您的输入,那么您可以考虑:
/^\$?\d{1,3}(?:,\d{3})*(?:\.\d{0,2})?$/gm
Other answers miss your requirement Value can also be without "," eg 12123212.00
其他答案未达到您的要求
Value can also be without "," eg 12123212.00
So I think you should go with:所以我认为你应该 go 与:
^(\d+|\d{1,3}(,\d{3})+)\.\d{2}$
Demo: https://regex101.com/r/FkWLjr/3演示: https://regex101.com/r/FkWLjr/3
Feel free to overload the syntax with non capturing groups if the capturing groups bother you.如果捕获组打扰您,请随意使用非捕获组重载语法。
If you want to allow amounts without decimal parts, just change \.\d{2}$
to (\.\d{2})?$
.如果您想允许没有小数部分的金额,只需将
\.\d{2}$
更改为(\.\d{2})?$
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.