`

正则表达式验证URL

 
阅读更多

 

JavaScript:

function isURL(str_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
	+ "((/?)|" // a slash isn't required if there is no file name
	+ "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$";
	var re=new RegExp(strRegex);
	//re.test()
	if (re.test(str_url)){
		return true;
	}else{
		return false;
	}
}

Java:

 

String VALID_URL = "^((https|http|ftp|rtsp|mms)?://)?" // schema
            + "(([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
            + "((/?)|" // a slash isn't required if there is no file name
            + "(/[0-9a-zA-Z_!~*\'().;?:@&=+$,%#-]+)+/?)$";
 

 

分享到:
评论
2 楼 fhqiwcw 2012-06-23  
marc0658 写道
这不是坑爹吗?我输入了一个http通过了。。。。。。。。。。。通过了。。。。。尼玛。。

欢迎改进
1 楼 marc0658 2012-06-18  
这不是坑爹吗?我输入了一个http通过了。。。。。。。。。。。通过了。。。。。尼玛。。

相关推荐

Global site tag (gtag.js) - Google Analytics