手机号码和身份证前三后四脱敏

public static String mobileEncrypt(String mobile){
    if(TextUtils.isEmpty(mobile) || (mobile.length() != 11)){
        return mobile;
    }
    return mobile.replaceAll("(\\d{3})\\d{4}(\\d{4})","$1****$2");
}

public static String idEncrypt(String id){
    if(TextUtils.isEmpty(id) || (id.length() < 8)){
        return id;
    }
    return id.replaceAll("(?<=\\w{3})\\w(?=\\w{4})", "*");
}

你可能感兴趣的:(JAVA,基础)