/**
* ? ?? 名字脫敏
* ? ?? 規(guī)則良姆,張三豐哀九,脫敏為:張*豐
* ? ? ?@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;
}
/**
* ? 身份證編號(hào)脫敏
* ? @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");
}
/**
* ?? ? 手機(jī)號(hào)脫敏
* ?? ? @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");
}