代码COPY
3. 使用正则
function geTel(tel){
var reg = /^(\d{3})\d{4}(\d{4})$/;
return tel.replace(reg, "$1****$2");
}
//测试
var tel = "17326453333";
console.log(geTel(tel));//173****3333
4. 通过长度截取
function geTel(tel){
return tel.substring(0, 3)+"****"+tel.substr(tel.length-4);
}
//测试
var tel = "17326453333";
console.log(geTel(tel));//173****3333