Page 1 of 1

Need quick help on this regex..

Posted: Thu May 04, 2006 1:07 pm
by seodevhead
I am building a regEx for URL validation and everything works great except one part. Here is my RegEx:

^((http)://)([[:alnum:]\-\.])+(\.)([[:alnum:]]){2,4}([[:alnum:]/+_\.~\-]*)$

Problem is it is allowing this:

http://...mysite.com

**Notice the dots after the http://

Any idea how I can alter my RegEx to cure this? Thanks for your help and time!

Posted: Thu May 04, 2006 1:26 pm
by jayshields
I'm a complete regex noob too, but at first glance, it seems you just need to remove a blackslash-dot...

Code: Select all

^((http)://)([[:alnum:]\-])+(\.)([[:alnum:]]){2,4}([[:alnum:]/+_\.~\-]*)$
I haven't tested it, so test it before you thank me, lol.

Posted: Thu May 04, 2006 1:57 pm
by seodevhead
Wow it works! Thank you so very much. I am in debt.

Posted: Thu May 04, 2006 2:03 pm
by nickvd
This is the one I use (but didnt write). I havn't been able to find a valid url that fails, or an invalid that passes...

Code: Select all

!^((http|https)\://)?([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&%\$\-]+)*@)*(localhost|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(\:[0-9]+)*(/[a-zA-Z0-9\./_-]*[a-zA-Z0-9\.\,\?\'\\\+&%\$#\=~_\-]*)*/*$!