Created
September 5, 2019 20:02
-
-
Save flynn1982/e23d95d81b7d60a979f98c824a533542 to your computer and use it in GitHub Desktop.
validate url or uri
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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