/*
* 手机效验
* 正确 true
* 错误 false
*/
public boolean isMobile(String mobiles) {
Pattern p = Pattern.compile("^1[3|4|5|7|8]\\d{9}$");
Matcher m = p.matcher(mobiles);
return m.matches();
}
/*
* 手机格式校验(11位)
* 正确 true
* 错误 false
*/
public boolean isPhone(String mobiles) {
Pattern p = Pattern.compile("1[3|5|7|8|][0-9]{9}");
Matcher m = p.matcher(mobiles);
return m.matches();
}
/*
* 纯数字效验
* 纯数字 true
* 非纯数字 false
*/
public boolean isNumber(String str)
{
java.util.regex.Pattern pattern=java.util.regex.Pattern.compile("[0-9]*");
java.util.regex.Matcher match=pattern.matcher(str);
return match.matches();
}
/*
* 数字字母效验
* 通过 true
* 不通过 false
*/
public boolean isNumberLetter(String str) {
if (Pattern.matches("^[0-9A-Za-z]{8,16}$", str)) {
return true;
} else {
return false;
}
}
/*
* 只能输入汉字,长度不限
* 通过 true
* 不通过 false
*/
public boolean ischinese(String str) {
if (Pattern.matches("^[\\u4E00-\\u9FA5\\uF900-\\uFA2D]+$", str)) {
return true;
} else {
return false;
}
}
/*
* 密码英文数字
* 通过 true
* 不通过 false
*/
public boolean isPassword(String str) {
if (Pattern.matches("[A-Za-z0-9]+", str)) {
return true;
} else {
return false;
}
}
/**
* 身份证编码校验
* @param idCard 校验身份证对象
* @return 不合法:true 合法:false
*/
public boolean isIdCardCheck(String idCard) {
if (!StringUtils.isEmpty(idCard) && Pattern.matches("\\d{15}|\\d{18}",idCard)) {
return true;
}
return false;
}
工具类-校验
最新推荐文章于 2023-12-27 17:38:01 发布