SOURCE

let bankAccount = '6212268202014638666'
// console.log(str)  //6212 **** **** 8666

const bankNumHandle = (bankNum) => {
    let reg = /^(.{4})(?:\d+)(.{4})$/
    let str =bankNum.replace(reg, '$1 **** **** $2')
    return str
}

console.log(bankNumHandle(bankAccount))

const noPassByName = (str) =>  {
    if (null != str && str != undefined) {
        if (str.length == 2) {
            return str.substring(0, 1) + '*' //截取name 字符串截取第一个字符,
        } else if (str.length == 3) {
            return str.substring(0, 1) + "*" + str.substring(2, 3) //截取第一个和第三个字符
        } else if (str.length > 3) {
            return str.substring(0, 1) + "*" + '*' + str.substring(3, str.length) //截取第一个和大于第4个字符
        }
    } else {
        return "";
    }
}
console.log(noPassByName('李阳'))
console.log(noPassByName('赵思晨'))
console.log(noPassByName('礼部尚书'))

const mobilePhoneHandle = (str) => {
    str += ''
    // let enStr = str.substring(0,3) + '****' + str.substring(str.length - 4)
    let enStr = str.replace(/^(.{3})(?:\d+)(.{4})$/, "$1****$2")
    return enStr
}
console.log(mobilePhoneHandle(17366661111))

const desensitizedIdNum= (idCard) => {
    if (idCard) {
        if (idCard.length === 15){
            idCard = idCard.replace(/^(.{4})(?:\d+)(.{4})$/, "$1******$2")
        }
        if (idCard.length === 18){
            idCard = idCard.replace(/^(.{8})(?:\d+)(.{4})$/, "$1******$2")
        }
    }
    return idCard
}
console.log(desensitizedIdNum('410110199708081122'))
console 命令行工具 X clear

                    
>
console