用js实现隐藏手机号中间四位
1.通过字符串截取
let phone = '18688886888' phone = phone.substring(0, 3) + '****' + phone.substr(phone.length - 4) console.log(phone)
2.使用正则
let phone = '18688886888' let reg = /^(\d{3})\d{4}(\d{4})$/ phone = phone.replace(reg, '$1****$2') console.log(phone)