JS脱敏姓名、身份证、电话、邮箱
一、姓名脱敏
handleName(name) { let arr = Array.from(name) let result = '' if (arr.length === 2) { result = arr[0] + '*' } else if (arr.length > 2) { for (let i = 1; i < arr.length - 1; i++) { arr[i] = '*' } result = arr.join("") }else { return name } return result },
二、电话脱敏
handlePhone (phone) { return phone.replace(/^(.{3})(?:\d+)(.{4})$/, "$1****$2") },
三、邮箱脱敏
handleEmail(email) { return email.replace(/^(.{0,3}).*@(.*)$/, "$1***@$2") },
四、身份证脱敏
handleIdCard(id) { return id.replace(/^(.{4})(?:\d+)(.{4})$/, "$1**********$2"); },