Sha256: e6a823b5ce093342cf447914b133a993b6ac1edab5f660e146171a517726ca7a
Contents?: true
Size: 618 Bytes
Versions: 2
Compression:
Stored size: 618 Bytes
Contents
class MacAddressValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) unless valid?(value) record.errors[attribute] << (options[:message] || I18n.t('yukonisuru.errors.messages.mac_address')) end end private def valid_format?(value) (value =~ /^([\h]{2}:){5}[\h]{2}?$/i) || (value =~ /^([\h]{2}[-|\.|\s]){5}[\h]{2}?$/i) || (value =~ /^([\h]{6})[-|\.][\h]{6}?$/i) || (value =~ /^([\h]{6}):[\h]{6}?$/i) || (value =~ /^([\h]{4}[-|\.|\s]){2}[\h]{4}?$/i) || (value =~ /^[\h]{12}?$/i) end def valid?(value) valid_format?(value) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
yukonisuru-1.0.0 | lib/yukonisuru/validators/mac_address_validator.rb |
yukonisuru-0.0.1 | lib/yukonisuru/validators/mac_address_validator.rb |