Skip to content

Instantly share code, notes, and snippets.

@flynn1982
Created September 5, 2019 20:02
Show Gist options
  • Save flynn1982/e23d95d81b7d60a979f98c824a533542 to your computer and use it in GitHub Desktop.
Save flynn1982/e23d95d81b7d60a979f98c824a533542 to your computer and use it in GitHub Desktop.
validate url or uri
def uri?(string)
uri = URI.parse(string)
%w( http https ).include?(uri.scheme)
rescue URI::BadURIError
false
rescue URI::InvalidURIError
false
end
See https://stackoverflow.com/questions/5331014/check-if-given-string-is-an-url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment