1、手机号
/^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/
2、姓名
/^[\u4e00-\u9fa5]{2,4}$/ //2-4个中文字符正则
3、身份证
/^[1-9]\d{5}(19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/
4、性别
/^[男|女]{1}$/
5、生日
/^\d{4}-\d{2}-\d{2}$/
6、银联信用卡卡号
/^62\d{14}$/
7、日期格式 yyyy-MM-dd
^\\d{4}-\\d{1,2}-\\d{1,2}
8、密码必须包含大小写字母与数字和特殊字符,最少8位
String regex = "^.*(?=.{8,16})(?=.*\\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*?_ ]).*$";
Pattern compilePhone = Pattern.compile("^(0\\d{2,3})-?(\\d{7,8})$");
Pattern compileTelephone = Pattern.compile("^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$");
Matcher matcherPhone = compilePhone.matcher(phone);
Matcher matcherTelephone = compileTelephone.matcher(phone);
if(matcherPhone.matches() || matcherTelephone.matches()){
log.info("号码:{}",phone);
}else{
throw new BusinessException("检查号码异常:"+phone);
}
如果写的有不对的地方,请大家指出来,我们一起进步,谢谢。