discourse/lib/validators/max_emojis_validator.rb

12 lines
348 B
Ruby
Raw Normal View History

class MaxEmojisValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
2018-03-05 09:35:24 -05:00
if Emoji.unicode_unescape(value).scan(/:([\w\-+]+(?::t\d)?):/).size > SiteSetting.max_emojis_in_title
record.errors.add(
attribute, :max_emojis,
max_emojis_count: SiteSetting.max_emojis_in_title
)
end
end
end