class HexValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) unless value =~ /^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/ record.errors[attribute] << (options[:message] || I18n.t('yukonisuru.errors.messages.hex')) end end end