在客户端怎么判断用户输入是一个合法的url

     怎么在客户端来判断用户输入的一个合法的url?http://www.xxxx.com?

用JS怎么写?

正则表达式:
[code="java"]/^http:\/\/[A-Za-z0-9]+.[A-Za-z0-9]+[\/=\?%-&_~`@[]\':+!]*([^\"\"])*$/.match('ttp://www.xxxx.com?')[/code]
返回true和false

楼上正解

网上找来的, 一个比较全的验证
[url]http://www.cnblogs.com/554006164/archive/2009/06/16/1504160.html[/url]
[code="js"]
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);

return (re.test(str_url));
} [/code]