I need to have a good regex for URL validation in javascript. After googling a number of websites, blogs and forums. The best I found is this blog post by Ivan Porto Carrero

I modified it a bit to make it valid in Javascript as shown below:

twitTxt = twitTxt.replace(/((ht|f)tp(s?)\:\/\/|~\/|\/)?(\w+:\w+@)?(([-\w]+\.)+(com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum|travel|[a-z]{2}))(:[\d]{1,5})?(((\/([-\w~!$+|.,=]|%[a-f\d]{2})+)+|\/)+|\?|#)?((\?([-\w~!$+|.,*:]|%[a-f\d{2}])+=([-\w~!$+|.,*:=]|%[a-f\d]{2})*)(&([-\w~!$+|.,*:]|%[a-f\d{2}])+=([-\w~!$+|.,*:=]|%[a-f\d]{2})*)*)*(#([-\w~!$+|.,*:=]|%[a-f\d]{2})*)?/, twitRegexCallback);

If you like it, a link back/comments would be much much appreciated 🙂

GD Star Rating

Incoming Search Term

Advertise Here

1 comment so far

Add Your Comment
  1. Really very informative post. Thanks for sharing it.