// 手机号码前三后四脱敏 public static String desensitizedPhone(String phone){ // 判断非空 org.apache.commons.lang3 if(StringUtils.isNotEmpty(phone)){ phone = phone.replaceAll("(\\w{3})\\w*(\\w{4})", "$1****$2"); } return phone
// 手机号码前三后四脱敏
public static String desensitizedPhone(String phone){
// 判断非空 org.apache.commons.lang3
if(StringUtils.isNotEmpty(phone)){
phone = phone.replaceAll("(\\w{3})\\w*(\\w{4})", "$1****$2");
}
return phone;
}
//身份证前三后四脱敏
public static String desensitizedIdCard(String idNumber){
if (StringUtils.isNotEmpty(idNumber)) {
if (idNumber.length() == 15){
idNumber = idNumber.replaceAll("(\\w{6})\\w*(\\w{3})", "$1******$2");
}
if (idNumber.length() == 18){
idNumber = idNumber.replaceAll("(\\w{6})\\w*(\\w{3})", "$1*********$2");
}
}
return idNumber;
}
结果展示:
【文章转自阿里云服务器代理商 http://www.558idc.com/aliyun.html 复制请保留原URL】