Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Michael Kohl <me@citizen428.net>
10 lines
341 B
Ruby
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
|