手机号13312341234转化成133 1234 1234
//方式一 function format_tel(tel){ tel = String(tel); return tel.replace(/(\d{3})(\d{4})(\d{4})/,function (rs,$1,$2,$3){ return $1+" "+$2+" "+$3 }); } //方式二 function format_tel(tel){ tel = String(tel); return tel.replace(/(\d{3})(\d{4})(\d{4})/,"$1 $2 $3"); }
(\d{3}\d{4}\d{4}) 可以匹配完整的手机号,并分别提取前3位、4-7位和8-11位,"$1 $2 $3" 是在三个结果集中间加空格组成新的字符串,然后替换完整的手机号。
标签:function,tel,手机号,银行卡,replace,return,格式化,String From: https://www.cnblogs.com/shichq/p/16891483.html