DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Validate A Url (regexp)

07.04.2005
| 142617 views |
  • submit to reddit
        
function isUrl(s) {
	var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	return regexp.test(s);
}

usage: if (isUrl("http://www.page.com")) alert("is correct") 
       else alert("not correct");    

Comments

Vetrichelvan Ch... replied on Tue, 2012/06/19 - 6:41am

Its very nice. 

Snippets Manager replied on Sun, 2008/07/13 - 7:19pm

Thanks for the regex above! Just what I needed. Sincerely, Alan Brown