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!
Need quick help on this regex..
Moderator: General Moderators
- seodevhead
- Forum Regular
- Posts: 705
- Joined: Sat Oct 08, 2005 8:18 pm
- Location: Windermere, FL
- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
I'm a complete regex noob too, but at first glance, it seems you just need to remove a blackslash-dot...
I haven't tested it, so test it before you thank me, lol.
Code: Select all
^((http)://)([[:alnum:]\-])+(\.)([[:alnum:]]){2,4}([[:alnum:]/+_\.~\-]*)$- seodevhead
- Forum Regular
- Posts: 705
- Joined: Sat Oct 08, 2005 8:18 pm
- Location: Windermere, FL
-
nickvd
- DevNet Resident
- Posts: 1027
- Joined: Thu Mar 10, 2005 5:27 pm
- Location: Southern Ontario
- Contact:
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\.\,\?\'\\\+&%\$#\=~_\-]*)*/*$!