1.验证是否是Email地址
public static boolean isEmail(String value) { String emailPattern = "^([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)*@([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)+[\\.][A-Za-z]{2,3}([\\.][A-Za-z]{2})?$"; Pattern p = Pattern.compile(emailPattern); Matcher m = p.matcher(value); return m.matches(); }
2.验证是否是手机号码
public static boolean isMobilePhone(String value) { String mobilePhonePattern = "^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$"; Pattern p = Pattern.compile(mobilePhonePattern); Matcher m = p.matcher(value); return m.matches(); }
时间: 2024-12-06 11:42:41