1.首字母为中英文,至少两个字符
/**姓名是否合法*/
public static boolean isLegalName(String mobiles) {
Pattern p = Pattern
.compile("^[\\u4e00-\\u9fa5a-zA-Z][\\u4e00-\\u9fa5a-zA-Z]+$");
Matcher m = p.matcher(mobiles);
System.out.println(m.matches() + "---");
return m.matches();
}
2.手机号码
public static boolean isMobileNO(String mobiles) {
/*
移动:134、135、136、137、138、139、150、151、157(TD)、158、159、187、188
联通:130、131、132、152、155、156、185、186
电信:133、153、180、189、(1349卫通)
总结起来就是第一位必定为1,第二位必定为3或5或8,其他位置的可以为0-9
*/
String telRegex = "[1][358]\\d{9}";//"[1]"代表第1位为数字1,"[358]"代表第二位可以为3、5、8中的一个,"\\d{9}"代表后面是可以是0~9的数字,有9位。
if (TextUtils.isEmpty(mobiles)) return false;
else return mobiles.matches(telRegex);
}
public static boolean isMobileNO(String mobiles){
Pattern p = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");
Matcher m = p.matcher(mobiles);
return m.matches();
}
String value="手机号";
String regExp = "^[1]([3][0-9]{1}|59|58|88|89)[0-9]{8}$";
Pattern p = Pattern.compile(regExp);
Matcher m = p.matcher(value);
return m.find();//boolean
3.邮政编码
String str = "^[1-9][0-9]{5}$";
/**
* 判断邮编
* @param paramString
* @return
*/
public static boolean isZipNO(String zipString){
String str = "^[1-9][0-9]{5}$";
return Pattern.compile(str).matcher(zipString).matches();
}
4.邮箱验证
public static boolean isEmail(String email){
if (null==email || "".equals(email)) return false;
//Pattern p = Pattern.compile("\\w+@(\\w+.)+[a-z]{2,3}"); //简单匹配
Pattern p = Pattern.compile("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");//复杂匹配
Matcher m = p.matcher(email);
return m.matches();
}
5.身份证验证
我国当前的身份证号分为三种:
一、15位身份证号
二、18位身份证号(前17位位数字,最后一位为字母x)
三、18为身份证号(18位都是数字)
具体验证请参考下面代码:
/**
* 验证身份证号是否符合规则
* @param text 身份证号
* @return
*/
public boolean personIdValidation(String text) {
String regx = "[0-9]{17}x";
String reg1 = "[0-9]{15}";
String regex = "[0-9]{18}";
return text.matches(regx) || text.matches(reg1) || text.matches(regex);
}
可参考:http://blog.csdn.net/dgs960825/article/details/51105344