简体   繁体   English

正则表达式用于验证固定范围的十进制数字

[英]Regex for validating decimal number with fixed range

I require a regex to validate fixed range decimal numbers eg 1234.1234 - valid, 4444.1234 - valid 123.123 - invalid, 1234.123 - invalid 我需要一个正则表达式来验证固定范围的十进制数字,例如1234.1234-有效,4444.1234-有效123.123-无效,1234.123-无效

The number 4 digit before decimal and 4 digit after decimal only valid. 小数点前4位数字和小数点后4位数字仅有效。 I'm currently uses this regex - /^\\S((\\d{4})((\\.\\d{4})?))$/ but this not satisfies me. 我目前正在使用此正则表达式-/ /^\\S((\\d{4})((\\.\\d{4})?))$/ . /^\\S((\\d{4})((\\.\\d{4})?))$/但我不满意。

^\d{4}(\.\d{4})?$

This should do it for you.Use 这应该为您做到。

^[1-9]\d{3}(\.\d{4})?$

If you dont want to match 0234.1234 如果您不想匹配0234.1234

You can use this regex: 您可以使用此正则表达式:

/^\d{4}(?:\.\d{4})?$/

This will match 1234 or 1234.5678 as valid matched. 这将匹配12341234.5678作为有效匹配项。

RegEx Demo 正则演示

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

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