我如何从正则表达式验证以下逻辑
允许的字符串示例:
不允许--$ 999999999.99(十进制前9位)-$ 99,99,999,99.99
意思是我只想限制小数点前的位数。我怎样才能做到这一点。提前致谢
您可以使用此正则表达式:
/^\$?(?:,?\d){1,8}(?:\.\d{1,2})?$/gm
解释:
^ # Line start
\$? # match optional $ at start
(?:,?\d) # Match an optional comma followed by a digit and use non-capturing group
{1,8} # up to 8 occurrence of previous group
(?:\.\d{1,2})? # followed by optional decimal point and 1 or 2 digits
$ # line end
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句