安卓基础--常用的正则表达式

2017-09-14 10:48:49来源:网络收集作者:管理员人点击

分享

public class RegExUtil {
//判空
public static boolean isNull(String msg){
if(msg==null||"".equals(msg)||msg.length()==0||"null".endsWith(msg.toLowerCase())){
return true;
}else{
return false;
}
}
//电话号码判断
public static boolean checkPhoneNum(String phoneNum){
Pattern patternPhone = Pattern.compile("^((13[0-9])|(147)|(15[0-9])|(18[0-9]))//d{8}$",
Pattern.CASE_INSENSITIVE);
Matcher matcherPhone = patternPhone.matcher(phoneNum);
return matcherPhone.matches();
}

//昵称判断(只能汉字、数字、字母)


public static boolean checkNick(String Nick){
Pattern patternPhone = Pattern.compile("^[/u4e00-/u9fa5a-zA-Z0-9]+$",
Pattern.CASE_INSENSITIVE);
Matcher matcherPhone = patternPhone.matcher(Nick);
return matcherPhone.matches();
}

//身份证号判断


public static boolean checkIDNumber(String IDnum){
Pattern patternPhone = Pattern.compile("(//d{14}[0-9a-zA-Z])|(//d{17}[0-9a-zA-Z])",
Pattern.CASE_INSENSITIVE);
Matcher matcherPhone = patternPhone.matcher(IDnum);
return matcherPhone.matches();
}

//姓名判断(只能输入汉字和字母)


public static boolean checkRealName(String realName){
Pattern name = Pattern.compile("^([A-Za-z]|[/u4E00-/u9FA5])+$",
Pattern.CASE_INSENSITIVE);
Matcher matcherPhone = name.matcher(realName);
return matcherPhone.matches();
}

//密码不能为汉字


public static boolean checkChinese(String password){
Patternp=Pattern.compile("[/u4e00-/u9fa5]");
Matcher m = p.matcher(password);
return m.matches();
}

// 判断车牌号


public staticboolean checkCarCode(String carcode){
String type = "[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$";
Pattern p=Pattern.compile(type);
Matcher m=p.matcher(carcode);
if(m.matches()){
return true;
}
return false;
}

}




最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台