項目中用到的數據脫敏處理Function,沒什麼墨水,都是項目裏拷貝出來保存的。
// 姓名脫敏
function hideName(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 "";
}
}
// 手機號碼脫敏
function hidePhone(phone) {
if (phone == null) {
return '未設置'
} else {
return phone.replace(/^(.{3})(?:\w+)(.{4})$/, "\$1****\$2");
}
}
// 身份證脫敏
function hideIdentity(Identity) {
return Identity.replace(/^(.{1})(?:\w+)(.{1})$/, "\$1****************\$2");
}
module.exports = {
hideName,
hidePhone,
hideIdentity
}