[英]Regex to validate only digits from 0-9, maximum of 8 digits till a dot and only two decimals as maximum
I haven't used regular expressions at all, so I'm having difficulty troubleshooting.我根本没有使用过正则表达式,所以我很难排除故障。 I'm looking for a regex that can help me to validate if there are only digits from 0-9, only 8 digits till a dot and two decimals as maximum.
我正在寻找一个正则表达式,它可以帮助我验证是否只有 0-9 的数字,只有 8 个数字直到一个点,最多有两个小数。
For example:例如:
33445566.09 33445566.09
/[0-9]/
/[0-9]{1,8}\.[0-9]{1,2}/
If you want to just match or not如果您只想匹配或不匹配
[0-9]
means match 0 or 1 or... 9 [0-9]
表示匹配 0 或 1 或... 9
{1,8}
means it can match minimum 1 and maximum 8 {1,8}
表示它可以匹配最小 1 和最大 8
\.
means escape.意味着逃跑。
If you want to get the group just use () in the regex如果您想获得该组,只需在正则表达式中使用 ()
/([0-9]{1,8})\.([0-9]{1,2})/
This way you can get 33445566
and 09
这样就可以得到
33445566
和09
Try this:尝试这个:
String input = "123456789.12";
Pattern pattern = Pattern.compile("^[0-9]{1,8}\\.[0-9]{1,2}$");
Matcher matcher = pattern.matcher(input);
System.out.println(matcher.matches()); //false
I think you need我想你需要
\d{1,8}(.\d{1,2})? \d{1,8}(.\d{1,2})?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.