//校验手机号/固话 function checkPhone(mobile) { mobile = mobile + ''; var tel = /^0\d{2,3}-?\d{7,8}$/; var phone = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/; if (mobile.length === 11) {//手机号码 if (phone.test(mobile)) { return true; } } else if (mobile.length === 12 && mobile.indexOf("-") !== -1) { if (tel.test(mobile)) { return true; } } return false; } //校验邮政编码 function checkPostcode(postcode) { if ( postcode === "") { return false; } else { if (! /^[0-9][0-9]{5}$/.test(postcode)) { return false; } } return true; } //校验email的合法性 function checkEmail(email) { if (email === "") { return false; } else { if (!/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/.test(email)) { return false; } } return true; } //验证url的格式合法性 function isUrl(str_url) { let strRegex = "^((https|http|ftp|rtsp|mms)?://)" + "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" // ftp的user@ + "(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP形式的URL- 199.194.52.184 + "|" // 允许IP和DOMAIN(域名) + "([0-9a-z_!~*'()-]+\.)*" // 域名- www. + "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." // 二级域名 + "[a-z]{2,6})" // first level domain- .com or .museum + "(:[0-9]{1,4})?" // 端口- :80 + "((/?)|" // a slash isn't required if there is no file name + "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$"; let re = new RegExp(strRegex); return re.test(str_url); }
原文:https://blog.csdn.net/bfboys/article/details/52863846
https://blog.csdn.net/UD_World/article/details/120462425
https://www.xp.cn/b.php/100124.html
标签:return,url,js,mobile,test,false,email,9a From: https://www.cnblogs.com/daytoy105/p/16721630.html