JS方式实现隐藏手机号码中间4位数

1.截取

   function test (value) {
      const start = value.slice(0, 3)
      const end = value.slice(-4)
      return `${start}****${end}`
    }

2.截取

    function test(value){
    const start = value.substring(0, 3)
    const end = value.substring(value.length-4)
    return `${start}****${end}`
}

3.正则

function test(value){
    var reg = /^(\d{3})\d{4}(\d{4})$/;  
    return value.replace(reg, "$1****$2");
}

 

posted @ 2021-08-12 16:54  tomingto  阅读(1198)  评论(0编辑  收藏  举报