标签:== char 截取 turn 5* length sub result 数字
var character = ‘sd13564349471中‘;//字符
//1.判断该字符串里是否包含数字
function getNum(text){
var value = text.replace(/[^0-9]/ig,"");
return value;
}
//2.if包含数字,判断数据长度是否为11
if(getNum(character).length == 11){
//3.截取所有数字,并用*替换4,4
var phNum = getNum(character),
phnumAfter = phNum.substr(0,3) + "****" + phNum.substr(7);
}
//4.替换输出
var result = character.replace(phNum,phnumAfter);
console.log(result)//结果 为sd135****9471中
标签:== char 截取 turn 5* length sub result 数字
原文地址:https://www.cnblogs.com/sakuar/p/13282849.html