public static void main(String[] args) {
String returnStr="10%";
String reg = "^([0-9.]+)[ ]*%$";
if(returnStr.matches(reg)){
System.out.println("是");
}else{
System.out.println("不是");
}
}
后台寫法:
String reg = "^([0-9.]+)[ ]*%$"; //注意編碼下的% ( %% )有可能不一致 把頁面返回來的%復制在"^([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"百分比格式錯誤!";
}
}
