Sha256: aa2b96c27f3d0f2833bb3d8efdf7740a51df126ae56a33b095bedaac1d281530

Contents?: true

Size: 433 Bytes

Versions: 272

Compression:

Stored size: 433 Bytes

Contents

# An ActiveRecord validator for any email field that you would use with effective_email or otherwise
#
# validates :cc, email_cc: true

class EmailCcValidator < ActiveModel::EachValidator
  PATTERN = /\A.+@.+\..+\Z/

  def validate_each(record, attribute, value)
    if value.present?
      unless value.to_s.split(',').all? { |email| PATTERN =~ email }
        record.errors.add(attribute, 'is invalid')
      end
    end
  end
end

Version data entries

272 entries across 272 versions & 1 rubygems

Version Path
effective_resources-2.27.2 app/validators/email_cc_validator.rb
effective_resources-2.27.1 app/validators/email_cc_validator.rb
effective_resources-2.27.0 app/validators/email_cc_validator.rb
effective_resources-2.26.5 app/validators/email_cc_validator.rb
effective_resources-2.26.4 app/validators/email_cc_validator.rb
effective_resources-2.26.3 app/validators/email_cc_validator.rb
effective_resources-2.26.2 app/validators/email_cc_validator.rb
effective_resources-2.26.1 app/validators/email_cc_validator.rb
effective_resources-2.26.0 app/validators/email_cc_validator.rb
effective_resources-2.25.16 app/validators/email_cc_validator.rb
effective_resources-2.25.15 app/validators/email_cc_validator.rb
effective_resources-2.25.14 app/validators/email_cc_validator.rb
effective_resources-2.25.13 app/validators/email_cc_validator.rb
effective_resources-2.25.12 app/validators/email_cc_validator.rb
effective_resources-2.25.11 app/validators/email_cc_validator.rb
effective_resources-2.25.10 app/validators/email_cc_validator.rb
effective_resources-2.25.9 app/validators/email_cc_validator.rb
effective_resources-2.25.8 app/validators/email_cc_validator.rb
effective_resources-2.25.7 app/validators/email_cc_validator.rb
effective_resources-2.25.6 app/validators/email_cc_validator.rb