1.姓名脱敏
desensitizationName(str) {
if (null != str && str != undefined) {
if (str.length <= 3) {
return "*" + str.substring(1, str.length);
} else if (str.length > 3 && str.length <= 6) {
return "**" + str.substring(2, str.length);
} else if (str.length > 6) {
return (str.substring(0, 2) + "****" + str.substring(6, str.length));
}
} else {
return "";
}
},
2.手机号脱敏
desensitizationPhone(str) {
if (null != str && str != undefined) {
var pat = /(\d{3})\d*(\d{4})/;
return str.replace(pat, "$1****$2");
}else {
return "";
}
},
3.身份证号脱敏
desensitizationIdCard(str) {
if (null != str && str != undefined) {
var pat = /(\d{4})\d*(\d{4})/;
return str.replace(pat, "$1***********$2");
} else {
return "";
}
},
4.邮箱脱敏
desensitizationEmail(email) {
let new_email = email;
if (String(email).indexOf("@") > 0) {
let str = email.split("@");
let _s = "";
if (str[0].length > 3) {
for (let i = 3; i < str[0].length; i++) {
_s += "*";
}
new_email = str[0].substr(0, 3) + _s + "@" + str[1];
} else {
for (let i = 1; i < str[0].length; i++) {
_s += "*";
}
new_email = str[0].substr(0, 1) + _s + "@" + str[1];
}
}
return new_email;
},