if(StringUtils.isNotEmpty(zjhm) ){
// String regularExpression = "(\\d{17}[0-9a-zA-Z]|\\d{14}[0-9a-zA-Z])";
String regularExpression="^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([\\d|x|X]{1})$";
Pattern pattern = Pattern.compile(regularExpression);
// Matcher matcher = pattern.matcher(zjhm);
String borthday =null ;
if ( !pattern.matcher(zjhm).matches() ){
result.setDesc("该客户证件号码格式错误");
return result;
}else{
borthday = zjhm.substring(6, 14);
if (StringUtils.isNotBlank(csrq) && !borthday.equals(String.valueOf(String.valueOf(csrq) ))){
result.setDesc("身份证和出生日期不匹配");
return result;
}
if (StringUtils.isNotEmpty(xb) ){ //单数表示男性,双数表示女性
String id17 = zjhm.substring(16, 17);
if (Integer.parseInt(id17) % 2 == 0) { //双数
if ( xb.equals("男")){
result.setDesc("身份证和性别不匹配");
return result;
}
} else {
if ( xb.equals("女")){
result.setDesc("身份证和性别不匹配");
return result;
}
}
}
}
}
if(StringUtils.isNotEmpty(lxdh)){
Pattern regex = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(17[0-9])|(18[0,5-9]))\\d{8}$");
Matcher m = regex .matcher(lxdh);
if(!m.matches()){
result.setDesc("联系电话格式错误");
return result;
}
}
if(StringUtils.isNotEmpty(email )){
String check = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
Pattern regex = Pattern.compile(check);
Matcher matcher = regex.matcher(email);
if(!matcher.matches()){
result.setDesc("邮箱格式错误");
return result;
}
}
java校验
最新推荐文章于 2024-03-14 11:11:08 发布