增加身份证脱敏

This commit is contained in:
wanggeng 2022-05-28 11:25:10 +08:00
parent 9cad965750
commit a0ad6332d5

View File

@ -65,4 +65,20 @@ public class IdCardUtil {
return age;
}
/**
* 身份证脱敏
*
* @param idCard
* @return
*/
public static String removeSensitive(String idCard) {
if (!RegexUtil.isIdentity(idCard)) {
throw new ParamsException("身份证格式错误");
}
if (idCard.length() == 15) {
return idCard.replaceAll("(\\w{6})\\w*(\\w{3})", "$1******$2");
}
return idCard.replaceAll("(\\w{6})\\w*(\\w{3})", "$1*********$2");
}
}