-3

Possible Duplicate:
What is the best regular expression to check if a string is a valid URL?

I want to validate text box by regular expression. It should be Null or valid Domain Name Like Google.com, example.com.

Thx

Community
  • 1
  • 1
Manoj Patil
  • 35
  • 1
  • 1
  • 9
  • heres a link for the regex http://stackoverflow.com/questions/161738/what-is-the-best-regular-expression-to-check-if-a-string-is-a-valid-url – megakorre May 19 '11 at 12:24

1 Answers1

1

Something along the following lines will work.

function isValidURL(url)
{
  return url.match(/([a-zA-Z]+:\/\/)?(.+\.)?(\w+)(\.\w+)(:[0-9]+)?(\/.+)?/) ? true : false;
}

alert(isValidURL(document.getElementById('textBoxId').value));

It won't work for things like "example.com" as really these aren't "valid" urls in that sense. A valid url beings with http://

Gary Green
  • 20,931
  • 6
  • 45
  • 74