1、手机号格式校验
let phoneReg = /^[1][3,4,5,7,8][0-9]{9}$/;
phoneReg.test(phoneNumber)
2、手机号前三位后添加空格,后面每隔四位添加空格
phoneAddGap(phoneNum){
let regPhoneNum = phoneNum.replace(/(\d{3})(\d{4})/, "$1 $2 "); //添加空格
return regPhoneNum;
}
本文介绍了如何使用正则表达式进行手机号码的格式验证,以及如何通过JavaScript函数为手机号码添加空格以提高可读性。具体包括:1. 使用正则表达式校验手机号码格式是否正确;2. 通过编写JavaScript函数,在手机号码的前三位和后续每四位数字之间添加空格。
let phoneReg = /^[1][3,4,5,7,8][0-9]{9}$/;
phoneReg.test(phoneNumber)
phoneAddGap(phoneNum){
let regPhoneNum = phoneNum.replace(/(\d{3})(\d{4})/, "$1 $2 "); //添加空格
return regPhoneNum;
}
5802

被折叠的 条评论
为什么被折叠?