Sha256: 23578dcfe58bb4a93db9a96943aca39ae657d8bbb4bb657106f29ac1f23c9d34
Contents?: true
Size: 488 Bytes
Versions: 1
Compression:
Stored size: 488 Bytes
Contents
class DomainNameValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) record.errors[attribute] << I18n.t("errors.messages.invalid") unless DomainName.new(value).valid? end end class DomainName def initialize(domain_name) @domain_name = domain_name end def valid? return true if @domain_name.nil? @domain_name =~ /^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ end def domain_name @domain_name end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
validates_host-0.1.0 | lib/validates_host/domain_name_validator.rb |