Sha256: 2f7c14d454a6135c923c4127e0330fe892d044c0e02526046ce0ba9a4db1173d
Contents?: true
Size: 607 Bytes
Versions: 2
Compression:
Stored size: 607 Bytes
Contents
class MacAddressValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) unless valid?(value) record.errors[attribute] << (options[:message] || I18n.t('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 |
---|---|
flash_validators-3.0.1 | lib/flash_validators/validators/mac_address_validator.rb |
flash_validators-3.0.0 | lib/flash_validators/validators/mac_address_validator.rb |