[英]What is the regex for decimals with or without leading zeros, and not one trailing zero?
I have this regex (for up to 3 numbers after the decimal): 我有这个正则表达式(小数点后最多3个数字):
/^(\d*[1-9]\d*(\.\d{1,3})?|0*\.\d{1,3})$/
I'm hoping to set these as valid : 我希望将它们设置为有效 :
And these as invalid : 而这些无效 :
This seems to do the trick 这似乎可以解决问题
^(0|[1-9]\d*)(\.\d{0,2}[1-9])?$
https://regex101.com/r/6ZKH3f/1/ https://regex101.com/r/6ZKH3f/1/
To only disallow .0
and accept eg .120
, 仅禁止.0
并接受.120
,
^(0|[1-9]\d*)(\.(?!0$)\d{1,3})?$
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.