Possible Duplicate:
What is the best regular expression to check if a string is a valid URL?
I wanted to validate URL taken from the user. Like http://www.google.com I wanted to validate last part of the URL (.com) I am continuously searching on the web but not found a correct answer. My code is:
function validate()
{
var url = document.getElementById("url").value;
var pattern = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
if (pattern.test(url)) {
alert("Valid Url");
return true;
}
alert("Please Input Right URL");
return false;
}