80,351
社区成员
发帖
与我相关
我的任务
分享
Pattern p = Pattern.compile("([0-9]|[1-9][0-9]|1[0-4][0-9])(\\.?|(\\.[1-9])*)|150");
public static boolean isScore(String score) {
if (score==null || score.length() ==0) return false;
Pattern p = Pattern.compile("([0-9]|[1-9][0-9]|1[0-4][0-9])(\\.[1-9])*|150");
Matcher m = p.matcher(score);
return m.matches();
}
测试结果
0=true
0.0=false
0.1=true
2.1=true
10=true
10.1=true
01=false
99.5=true
100.1=true
129=true
150=true
150.5=false
200=false
.0为非法,如果需要.0合法用下面的
public static boolean isScore(String score) {
if (score==null || score.length() ==0) return false;
Pattern p = Pattern.compile("([0-9]|[1-9][0-9]|1[0-4][0-9])(\\.[1-9])*|150");
Matcher m = p.matcher(score);
return m.matches();
}