JAVA验证字段正则表达式相关
/**
*邮箱格式验证
*/
public static boolean checkEmail(String email){
boolean flag = false;
try{
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);
flag = matcher.matches();
}catch(Exception e){
flag = false;
}
return flag;
}
/**
* 手机号码格式验证
*/
public static boolean checkMobile(String mobile){
boolean flag = false;
try{
Pattern regex = Pattern.compile("^1[3|4|5|7|8][0-9]\\d{4,8}$");
Matcher matcher = regex.matcher(mobile);
flag = matcher.matches();
}catch(Exception e){
flag = false;
}
return flag;
}
/**
* 姓名格式验证
* @param mobile
* @return
*/
public static boolean checkName(String name){
boolean flag = false;
try{
Pattern regex = Pattern.compile("^(([\u4e00-\u9fa5]{2,8})||([a-zA-Z]{2,16}))$");
Matcher matcher = regex.matcher(name);
flag = matcher.matches();
}catch(Exception e){
flag = false;
}
return flag;
}
/**
* 地址格式验证
* @param mobile
* @return
*/
public static boolean checkAdress(String name){
boolean flag = false;
try{
Pattern regex = Pattern.compile("^([\u4e00-\u9fa50-9]{2,30})$");
Matcher matcher = regex.matcher(name);
flag = matcher.matches();
}catch(Exception e){
flag = false;
}
return flag;
}
/**
* 电话号码格式验证
* @param mobile
* @return
*/
public static boolean checkPhone(String phone){
boolean flag = false;
try{
Pattern regex = Pattern.compile("^(\\(?\\d{3,4}[-\\)]?\\d{7,8})$");
Matcher matcher = regex.matcher(phone);
flag = matcher.matches();
}catch(Exception e){
flag = false;
}
return flag;
}
/**
* 可输字符,字母,数字格式验证
* @param mobile
* @return
*/
public static boolean checkAll(String name){
boolean flag = false;
try{
Pattern regex = Pattern.compile("^([\u4e00-\u9fa50-9a-zA-Z]{2,30})$");
Matcher matcher = regex.matcher(name);
flag = matcher.matches();
}catch(Exception e){
flag = false;
}
return flag;
}