JavaScript正则表达式验证手机号码
JavaScript正则表达式验证手机号码
号段来源:https://www.jihaoba.com/tools/haoduan/
// 找到号段
let mobileNodes = document.querySelector('.hd_result').querySelectorAll('font');
// 组装字符串
let mobiles = [];for(mobile of mobileNodes){
mobiles.push(mobile.innerText);
}
mobiles.join('|');
"139|138|137|136|134|135|147|150|151|152|157|158|159|172|178|182|183|184|187|188|195|197|198|130|131|132|140|145|146|155|156|166|185|186|175|176|196|133|149|153|177|173|180|181|189|191|193|199|162|165|167|170|171"
checkMobile(){
let regMobile = /^(139|138|137|136|134|135|147|150|151|152|157|158|159|172|178|182|183|184|187|188|195|197|198|130|131|132|140|145|146|155|156|166|185|186|175|176|196|133|149|153|177|173|180|181|189|191|193|199|162|165|167|170|171)\d{8}$/;
if (!regMobile.test(userKey)) {
uni.showToast({
title: "请输入正确的手机号码!",
icon: "none",
duration: 1500,
});
return false;
}
}