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

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){
Pattern  p=Pattern.compile("[\u4e00-\u9fa5]");
 Matcher m = p.matcher(password); 
return m.matches();
}

// 判断车牌号

public static  boolean 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;
}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值