我尝试使用java regex检查印尼格式编号。但我有一些问题要做。问题是我的正则表达式无法检测0,12和2.005.000作为数字(true)。
以下印尼格式的有效数字:
1
15
0,12
123.621
2.005.000
这是我的代码:
Pattern doublePattern = Pattern.compile("[-+]?\\d*\\.?\\d+");
System.out.println("1 is "+doublePattern.matcher("1").matches());
System.out.println("15 is "+doublePattern.matcher("15").matches());
System.out.println("0,12 is "+doublePattern.matcher("0,12").matches());
System.out.println("123.621 is "+doublePattern.matcher("123.621").matches());
System.out.println("2.005.000 is "+doublePattern.matcher("2.005.000").matches());
结果/输出程序:
1是真的
15是真的
0,12 false
123.621是真的
2.005.000 false
0,12和2.005.000为假(未检测为数字)。我认为我的正则表达式是错误的。