Skip to content

Instantly share code, notes, and snippets.

@ctcherry
Created November 16, 2009 19:22
Show Gist options
  • Save ctcherry/236251 to your computer and use it in GitHub Desktop.
Save ctcherry/236251 to your computer and use it in GitHub Desktop.
Regular expression to validate URLs
Regular expression to validate URLs
^https?\:\/\/[a-z0-9\-]+(\.[a-z0-9\-]+)+(\:\d{1,5})?(/|/[a-z0-9\_\-\/\?\=\.]*)?$
VALID
http://chrischerry.name
https://chrischerry.name
http://chrischerry.name/
http://chrischerry.name:1234/
http://chrischerry.name:1234/somefile.rb
http://chrischerry.name:1234/somefile.rb?things=stuff
INVALID
http://onepart
http://doubledot..com
ftp://wrongprotocol.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment