2

日常常用功能,需要累积

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

思路1、运用正则匹配前三位,后四位,然后用string replace方法替换

var phone = '18801333333';
var reg = /^(\d{3})\d{4}(\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);

D一生
235 声望15 粉丝

一如前端深似海