class ColorSchemaValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    unless value =~ /^#(\h{6}|\h{3})$/
      record.errors.add(attribute, options[:message] || :invalid)
    end
  end
end

class ColorSchemaValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    unless value =~ /\A#(\h{6}|\h{3})\z/
      record.errors.add(attribute, options[:message] || :invalid)
    end
  end
end

Fix regexp to more strong
Fix regexp to more strong

According to the following error on Rails 4:

    ArgumentError: The provided regular expression is using multiline anchors (^ or $), which may present a security risk. Did you mean to use \A and \z, or forgot to add the :multiline => true option?
    from /some/where/vendor/bundle/ruby/2.2.0/gems/activemodel-4.2.3/lib/active_model/validations/format.rb:39:in `check_options_validity'
