废话不多说,直接上代码了
// 手机号码前三后四脱敏
public static String mobileDesensitize(String mobile) {
if (StringUtils.isEmpty(mobile) || (mobile.length() != 11)) {
return mobile;
}
return mobile.replaceAll("(\\w{3})\\w*(\\w{4})", "$1****$2");
}
// 身份证前三后四脱敏
public static String identityDesensitize(String identity) {
if (StringUtils.isEmpty(identity) || (identity.length() != 18)) {
return identity;
}
return identity.replaceAll("(\\w{3})\\w*(\\w{4})", "$1****$2");
}