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)

  • 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("")) alert("is correct") 
       else alert("not correct");    


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

Its very nice. 

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

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