rails check if a URL is valid
require 'uri'
url =~ URI::regexp
# => 0 if it match, nil if not
rails check if a URL is valid
require 'uri'
url =~ URI::regexp
# => 0 if it match, nil if not
check validate url ruby
require "net/http"
def url_exist? url_string
Timeout.timeout 3 do # set timeout 3s because some invalid url take long time to respond
url = URI.parse url_string
new_url = url.scheme || "http://#{url_string}"
url = URI.parse new_url if url.scheme.nil?
req = Net::HTTP.new url.host, url.port
req.use_ssl = url.scheme == 'https'
path = url.path if url.path.present?
res = req.request_head(path || '/')
res.code != "404"
end
rescue
false
end
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us