JavaScript 手机号码脱敏

日常常用功能,需要累积

假设目前有个手机号
var phone = '18801333333'=> 188**3333

思路1、运用正则匹配前三位,后四位,然后用string replace方法替换
`var phone = '18801333333';
var reg = /^(d{3})d*(d{4})/;
var newPhone = phone.replace(reg,'$1****$2');
console.log(newPhone);
`
思路2、运用string api
`var phone = '18801333333';
var newPhone = phone.substr(0,3) + '**' + phone.substr(7);
console.log(newPhone);
`

你可能感兴趣的:(javascript前端)