首页 > 代码库 > JS 验证URL

JS 验证URL

var strVal = $("#urlText").val();var Expression = "^((https|http|ftp|rtsp|mms)?://)"+ "?(([0-9a-zA-Z_!~*‘().&=+$%-]+: )?[0-9a-zA-Z_!~*‘().&=+$%-]+@)?" //ftp的user@+ "(([0-9]{1,3}\\.){3}[0-9]{1,3}" // IP形式的URL- 199.194.52.184+ "|" // 允许IP和DOMAIN(域名)+ "([0-9a-zA-Z_!~*‘()-]+\\.)*" // 域名- www.+ "([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z]\\." // 二级域名+ "[a-zA-Z]{2,6})" // first level domain- .com or .museum+ "(:[0-9]{1,4})?" // 端口- :80+ "((/?)|"+ "(/[0-9a-zA-Z_!~*‘().;?:@&=+$,%#-]+)+/?)$";var urlReg = new RegExp(Expression);var flag = !!(strVal.toLowerCase()).match(urlReg);if (!flag) {alert("请输入正确的链接地址!");$("#urlText").select();return;}

 

JS 验证URL