标签:color ons 截取 pre replace function 判断 bst console
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中
标签:color ons 截取 pre replace function 判断 bst console
原文地址:http://www.cnblogs.com/rockyan/p/7904297.html