1、问题:如何在后台验证百分比数据?
2、百分比的正则表达式:([0-9.]+)[ ]*%,也可以写成:^([0-9.]+)[ ]*%$
3、后台写法:
public class abc {
@Test
public void main(){
testabc();
}
public int testabc(){
String returnStr="50%";
String reg = "^([0-9.]+)[ ]*%$";
if(returnStr.matches(reg))
{
System.out.println(1);
return 1;
}
else{
System.out.println(0);
return 0;
}
}
}
本文介绍了一种用于验证百分比数据格式正确性的正则表达式,并提供了Java代码示例,演示了如何使用该正则表达式检查字符串是否符合百分比格式。
2万+

被折叠的 条评论
为什么被折叠?



