天天看點

比較強大的比對URL的正規表達式

var 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

+ "/$" //end with the /

//+ "((/?)|" // a slash isn't required if there is no file name

//+ "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$";

var reg=new RegExp(strRegex);

if(!reg.test(jforumUrl.val()))

{

alert("URL比對失敗,請以http://開頭,以/結尾!");

return false;

}

繼續閱讀