Sha256: e7eea0493f4d1bf0eebf4f5ec798500d39c80e3832c701eff7c89cbfa0e11610
Contents?: true
Size: 603 Bytes
Versions: 2
Compression:
Stored size: 603 Bytes
Contents
module Validators class Hostname def self.valid?(host) host = host.to_s uri = URI(host) host.present? && uri.host.nil? && uri.scheme.nil? && uri.fragment.nil? && uri.query.nil? && uri.path == host && host.split(".").all? {|label| valid_label?(label) } && host.size <= 255 && Validators::TLD.host_with_valid_tld?(host) rescue URI::InvalidURIError false end def self.valid_label?(label) !label.start_with?("-") && !label.match(/\A\d+\z/) && label.match(/\A[a-z0-9-]{1,63}\z/i) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
validators-2.8.1 | lib/validators/hostname.rb |
validators-2.8.0 | lib/validators/hostname.rb |