/**
* 名字脱敏
* 规则,张三丰,脱敏为:张*丰
* @param name
* @return
*
*/
public static StringnameDesensitization(String name) {
if (name ==null || name.isEmpty()) {
return "";
}
String myName =null;
char[] chars = name.toCharArray();
if (chars.length ==1) {
myName = name;
}
if (chars.length ==2) {
myName = name.replaceFirst(name.substring(1), "*");
}
if (chars.length >2) {
myName = name.replaceAll(name.substring(1, chars.length -1), "*");
}
return myName;
}
/**
* 身份证编号脱敏
* @param idNo
* @return
*
*/
public static StringidNoDesensitization(String idNo) {
if (idNo ==null || idNo.isEmpty()) {
return "";
}
return idNo.replaceAll("(\\d{6})\\d{8}(\\w{4})", "$1********$2");
}
/**
* 手机号脱敏
* @param mobile
* @return
*
*/
public static StringmobileDesensitization(String mobile) {
if (mobile ==null || mobile.isEmpty()) {
return "";
}
return mobile.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
}
网友评论