Sha256: f273aa366f21c10e2f469b6ee212554d9a9e116ea6348b261cd8427e13272aa2
Contents?: true
Size: 753 Bytes
Versions: 2
Compression:
Stored size: 753 Bytes
Contents
# rubocop:disable Style/AsciiComments module Emoji module Validator # Validate an attribute against emojis # ```ruby # class Person < ApplicationRecord # validates :first_name, no_emoji: true # end # # person = Person.new(first_name: "John", last_name: "😃") # person.valid? #true # person.first_name = "😃" # person.valid? #false # ``` class NoEmojiValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) return if value.match(Unicode::Emoji::REGEX_ANY).nil? record.errors.add(attribute, :has_emojis) end end end end ActiveModel::Validations::NoEmojiValidator = Emoji::Validator::NoEmojiValidator # rubocop:enable Style/AsciiComments
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
emoji-validator-0.1.1 | lib/emoji/validator/no_emoji_validator.rb |
emoji-validator-0.1.0 | lib/emoji/validator/no_emoji_validator.rb |