隐藏手机号中间四位,改为**** (常见四种方法)

Posted renzm0318

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了隐藏手机号中间四位,改为**** (常见四种方法)相关的知识,希望对你有一定的参考价值。

 

var phone=13511115678;
//方法一
var newphone=phone.substr(0, 3) + **** + phone.substr(phone.length - 4);
//方法二
var newphone= phone.replace(phone.substr(3, 4),"****")
//方法三
var newphone=phone.replace(/(\\d{3})\\d{4}(\\d{4})/, $1****$2);
//方法四
var newphone=phone.replace( /([0-9]{3})([0-9]{4})([0-9]{4})/,"$1****$3")

详解方法三和四,如下:

技术图片

 

以上是关于隐藏手机号中间四位,改为**** (常见四种方法)的主要内容,如果未能解决你的问题,请参考以下文章