docbrown/app/validators/emoji_only_validator.rb
dependabot[bot] 2d98e3346b
Bump rubocop from 1.23.0 to 1.24.0 (#15872)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Michael Kohl <me@citizen428.net>
2021-12-27 10:04:59 -05:00

10 lines
341 B
Ruby

class EmojiOnlyValidator < ActiveModel::EachValidator
DEFAULT_MESSAGE = "contains non-emoji characters or invalid emoji".freeze
def validate_each(record, attribute, value)
return unless value
return if value.gsub(EmojiRegex::RGIEmoji, "").blank?
record.errors.add(attribute, options[:message] || DEFAULT_MESSAGE)
end
end