Sha256: 3f8ee514be182cd3f00601ab0f314e3e1ace6aebe88fec982bcd9877cd6d9ee9
Contents?: true
Size: 420 Bytes
Versions: 4
Compression:
Stored size: 420 Bytes
Contents
# Checks if the value of an attribute is a valid hex color. # # @example Validate that the product color is a valid hex color. # class Product << ActiveRecord::Base # attr_accessor :color # validates :color, color: true # end class ColorValidator < BaseValidator private HEX_COLOR_FORMAT = /^#(?:[0-9a-f]{3})(?:[0-9a-f]{3})?$/i def valid?(color, _) (color =~ HEX_COLOR_FORMAT).present? end end
Version data entries
4 entries across 4 versions & 1 rubygems