/**
* 身份证号脱敏
* 脱敏规则: 保留前六后三, 适用于15位和18位身份证号
* @param idNumber
* @author cy
* @since 2022-04-22
/
public static String desensitizedIdNumber(String idNumber){
if (StringUtil.isStrNotEmpty(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;
}
/**
* 手机号加*号
* @param realPhone
* @return
*/
public static String rePhone(String realPhone) {
String phoneNumber;
if (realPhone.length() == 11){
phoneNumber = realPhone.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
}else{
phoneNumber = realPhone;
}
return phoneNumber;
}
标签:手机号,身份证号,idNumber,realPhone,phoneNumber,脱敏,String
From: https://www.cnblogs.com/codeLearn/p/17349759.html