一些正则判断 - 验证是否是正确的手机号码/身份证/隐藏中间几位数字

/**
     * 验证手机格式
     */
    public static boolean isMobileNO(String mobiles) {
        String telRegex = "[1][345678]\\d{9}";// "[1]"代表第1位为数字1,"[3578]"代表第二位可以为3、5、8中的一个,"\\d{9}"代表后面是可以是0~9的数字,有9位。
        if (TextUtils.isEmpty(mobiles))
            return false;
        else
            return mobiles.matches(telRegex);
    }
/**
     * 验证密码格式
     */
    public static boolean isPwd(String pwd) {
        // 8-16位. 16位已在maxLength中显示
        // 后来改成了6-16位. 已改
        if (pwd.length() < 6) {
            return false;
        } else {
            return true;
        }
    }
/**
     * 验证身份证号码
     */
    public static boolean personIdValidation(String text) {
        String regx = "[0-9]{17}[Xx]";
        String reg1 = "[0-9]{15}";
        String regex = "[0-9]{18}";
        return text.matches(regx) || text.matches(reg1) || text.matches(regex);
    }
/**
     * 隐藏手机号中间四位
     *
     * @param mobile
     * @return
     */
    public static String HideMobile(String mobile) {
        StringBuilder sb = new StringBuilder();
        if (!TextUtils.isEmpty(mobile) && mobile.length() > 6) {

            for (int i = 0; i < mobile.length(); i++) {
                char c = mobile.charAt(i);
                if (i >= 3 && i <= 6) {
                    sb.append('*');
                } else {
                    sb.append(c);
                }
            }

        }
        return sb.toString();
    }
/**
     * 身份证号 隐藏 年月日  从第9-16
     */
    public static String HideIdentity(String number) {
        StringBuilder sb = new StringBuilder();
        if (!TextUtils.isEmpty(number) && number.length() > 16) {
            for (int i = 0; i < number.length(); i++) {
                char c = number.charAt(i);
                if (i >= 8 && i <= 15) {
                    sb.append('*');
                } else {
                    sb.append(c);
                }
            }
        }
        return sb.toString();
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值