// 手机号分隔显示
let tel = this.data.tel_value // 原始手机号
let len = tel_value.length // 原始手机号的长度
let mobile = ''
for (var i = 0; i < len; i++) {
if (i == 2 || i == 6) {
mobile = mobile + tel.charAt(i) + " ";
}
else {
mobile = mobile + tel.charAt(i);
}
}
- 正则
<script>
var str = '13212345678';
var newstr = '';
newstr = str.replace(/\s/g, '').replace(/(^\d{3})(?=\d)/g, "$1 ").replace(/(\d{4})(?=\d)/g, "$1 ");
console.log(newstr);
</script>
- 手机号格式校验
let reg = /^[1][1,3,4,5,6,7,8,9][0-9]{9}$/ //正则验证手机号