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")
详解方法三和四,如下:
原文地址:https://www.cnblogs.com/renzm0318/p/10919543.html
时间: 2024-10-08 11:16:02