Sha256: b53a6c3fdb4411b26b1edd6a09a8fc2e8e7aeab9936f74258a3334ff631823da
Contents?: true
Size: 447 Bytes
Versions: 1
Compression:
Stored size: 447 Bytes
Contents
class IpValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) record.errors[attribute] << I18n.t("errors.messages.invalid") unless Ip.new(value).valid? end end class Ip def initialize(ip) @ip = ip end def valid? return true if @ip.blank? @ip =~ /^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$/ end def ip @ip end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
validates_host-0.1.0 | lib/validates_host/ip_validator.rb |