正则表达式验证格式 手机、邮箱、字符串

手机号码验证
    public static boolean isMobileNO(String mobiles) {
        try {
            Pattern p = Pattern
                    .compile("(13[0-9]|14[57]|15[012356789]|18[02356789])\\d{8}");
            Matcher m = p.matcher(mobiles);
            return m.matches();
        } catch (Exception e) {
            return false;
        }
    }
验证邮箱地址是否正确
    public static boolean checkEmail(String email) {
        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);
            return matcher.matches();
        } catch (Exception e) {
            return false;
        }
    }
检测字符串中是否包含汉字
    public static boolean checkChinese(String sequence) {
        final String format = "[//u4E00-//u9FA5//uF900-//uFA2D]";
        boolean result = false;
        Pattern pattern = Pattern.compile(format);
        Matcher matcher = pattern.matcher(sequence);
        result = matcher.find();
        return result;
    }
检测字符串中只能包含:中文、数字、下划线(_)、横线(-)
   public static boolean checkNickname(String sequence) {
        final String format = "[^//u4E00-//u9FA5//uF900-//uFA2D//w-_]";
        Pattern pattern = Pattern.compile(format);
        Matcher matcher = pattern.matcher(sequence);
        return !matcher.find();
    } 
获取中间有*号的手机号
   public static String getPhonePass(String phone) {
        if (null == phone || "".equals(phone) || phone.length() < 11) {
            return "";
        }

        String passA = phone.substring(0, 3);
        String passB = phone.substring(phone.length() - 3, phone.length());
        return passA + "*****" + passB;
    }
获取中间有*号的身份证号
    public static String getPidPass(String pid) {
        if (null == pid || "".equals(pid) || pid.length() < 18) {
            return "";
        }

        String passA = pid.substring(0, 3);
        String passB = pid.substring(pid.length() - 3, pid.length());
        return passA + "*****" + passB;
    }






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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值