验证只包含中英文和数字的字符串
/**
* 验证只包含中英文和数字的字符串
*
* @param keyword
* @return
*/
public static Boolean validKeyword(String keyword) {
String regex = "^[a-zA-Z0-9\u4E00-\u9FA5]+$";
Pattern pattern = Pattern.compile(regex);
Matcher match = pattern.matcher(keyword);
return match.matches();
}
判断是否是邮箱
/**
* 匹配邮箱正则
*/
private static final Pattern VALID_EMAIL_ADDRESS_REGEX =
Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE);
/**
* 判断是否是邮箱
*
* @param emailStr
* @return
*/
public static boolean isEmail(String emailStr) {
Matcher matcher = VALID_EMAIL_ADDRESS_REGEX.matcher(emailStr);
return matcher.find();
}
判断是否是网址
/**
* 判断是否是网址
*
* @param urlString
* @return
*/
public static boolean isURL(String urlString) {
String regex = "^([hH][tT]{2}[pP]:/*|[hH][tT]{2}[pP][sS]:/*|[fF][tT][pP]:/*)(([A-Za-z0-9-~]+).)+([A-Za-z0-9-~\\/])+(\\?{0,1}(([A-Za-z0-9-~]+\\={0,1})([A-Za-z0-9-~]*)\\&{0,1})*)$";
Pattern pattern = Pattern.compile(regex);
if (pattern.matcher(urlString).matches()) {
return true;
} else {
return false;
}
}
判断是否为11位电话号码
/**标签:常用,return,String,Pattern,正则,static,matcher,pattern,工具 From: https://blog.51cto.com/u_15461374/5938254
* 判断是否为11位电话号码
*
* @param phone
* @return
*/
public static boolean isPhone(String phone) {
Pattern pattern = Pattern.compile("^((13[0-9])|(14[5,7])|(15[^4,\\D])|(17[0-8])|(18[0-9]))\\d{8}$");
Matcher matcher = pattern.matcher(phone);
return matcher.matches();
}