public static void main(String[] args) {
String returnStr="10%";
String reg = "^([0-9.]+)[ ]*%$";//注意编码下的%有可能不一致 把页面返回来的%复制在"^([0-9.]+)[ ]*%$"就可以了
if(!returnStr.matches(reg))
{
System.out.println(Y);
}else{
System.out.println(N);
}
}
后台写法:
String reg = "^([0-9.]+)[ ]*%$";
String test= (String) params.get("test");
if(!test.matches(reg)){ //test代表返回的百分比参数
return"百分比格式错误!";
}
//如果返回来的是多个百分比就循环
String[] str = test.split("\\,");
for(int z=0;z<str.length;z++){
if(!str[z].matches(reg)){
return"百分比格式错误!";
}
}
原文:https://www.cnblogs.com/duoyan/p/11648969.html