// js判断是否是手机号码格式
function isPhone(str) {
var reg = /^1(3|4|5|6|7|8|9)\d{9}$/;
return reg.test(trim(str, 'g'));
}
js格式化手机号:
// 手机号码格式转化为 344 格式 (130 1234 5678)
function phoneSeparated(phoneNumber) {
let tel = trim(phoneNumber, 'g');
if (isPhone(tel)) {
tel = tel.substring(0, 3) + ' ' + tel.substring(3, 7) + ' ' + tel.substring(7, 11);
}
return tel;
}
phoneSeparated("13012345678") // "130 1234 5678"