前端页面常见小技巧

js常用正则

2017-08-17  本文已影响0人  小姜先森o0O

匹配邮箱:

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

匹配中文:

var pattern = /[\u4e00-\u9fa5]/,
str = '';
console.log(pattern.test(str));

匹配时间:

var pattern = /([01]?\d|2[0-3]):[0-5]?\d:[0-5]?\d/,
str = '';
console.log(pattern.test(str));

匹配IP(IPV4):

var pattern = /(\d+)\.(\d+)\.(\d+)\.(\d+)/,
str = '';
console.log(pattern.test(str));

匹配身份证号码:

var pattern = /\d{15}|\d{17}[0-9Xx]/,
str = '';
console.log(pattern.test(str));

匹配手机号:

var pattern = /(13\d|14[57]|15[^4,\D]|17[13678]|18\d)\d{8}|170[0589]\d{7}/,
str = '';
console.log(pattern.test(str));
上一篇下一篇

猜你喜欢

热点阅读