手机号中间4位数替换为*

// 替换手机号中间四位

var str = '15912341234';
// 方法一
str.replace(/(\d{3})(\d{4})(\d{3})/, function($0, $1, $2, $3){
console.log($1+"****"+$3)
})
// 方法二
str.replace(str.substr(3,4), '*'.repeat(4));
// 方法三
str.substr(0,3)+"*".repeat(4)+str.substr(7)

posted @ 2019-05-28 18:52  北执666  阅读(517)  评论(0编辑  收藏  举报