正则判断的公共方法包括(手机号,邮箱,密码,ip等)
话不多说直接上代码,欢迎大家的随时补充
function checkType(str, type) {
switch (type) {
case 'email':
return /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/.test(str);
case 'phone':
return /^1[3|4|5|7|8|9|6][0-9]{9}$/.test(str);
case 'tel':
return /^(0\d{2,3}-\d{7,8})
原创
2021-03-17 10:42:14 ·
160 阅读 ·
0 评论