首页 > 编程语言 > 详细

Java 在后台用正则表达式验证百分比数据

时间:2019-10-10 16:58:03      阅读:113      评论:0      收藏:0      [点我收藏+]

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"百分比格式错误!";
}
}

 

 

Java 在后台用正则表达式验证百分比数据

原文:https://www.cnblogs.com/duoyan/p/11648969.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!