JS 正则匹配手机号码、邮箱等

2018-09-05  本文已影响0人  Charles_Zhang

匹配手机号码

var pattern = /(13\d|14[579]|15[^4\D]|17[^49\D]|18\d)\d{8}/g;
var str = 'xxx';
console.log(pattern.test(str));

匹配邮箱

var pattern = /\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}/g;
var str = 'xxx';
console.log(pattern.test(str));

匹配身份证

var pattern = /\d{17}[0-9Xx]|\d{15}/g;
var str = 'xxx';
console.log(pattern.test(str));
上一篇下一篇

猜你喜欢

热点阅读