用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)

 

posted @ 2020-09-19 14:20  无痕-范特西  阅读(1287)  评论(0编辑  收藏  举报