姓名,手机号,身份证号三要素脱敏
2019-12-20 本文已影响0人
此行欲上天
const getStr = (str, startIndex, endIndex, code) => {
let sliceStr = str.slice(startIndex, endIndex)
let replaceStr = ''
let len = sliceStr.length
let i = -1
while(++i < len) {
replaceStr += code
}
return str.replace(sliceStr, replaceStr)
}
// 手机号
const getPhone = phone => getStr(phone, 3, 7, '*');
// 身份证号
const getIdCard = idCard => getStr(idCard, 6, 14, '*');
// 姓名
const getName = name => {
let startIndex = Math.floor(name.length / 2);
return getStr(name, startIndex, name.length, '*')
}