Sha256: e717e339a284375aad4e3388adbe251fb04c91768e7f9ef96cc64acbc99c5b79
Contents?: true
Size: 1.14 KB
Versions: 3
Compression:
Stored size: 1.14 KB
Contents
require 'active_model' require 'active_model/validations' require 'mail' require 'valid_email/validate_email' class EmailValidator < ActiveModel::EachValidator def validate_each(record,attribute,value) begin return if options[:allow_nil] && value.nil? return if options[:allow_blank] && value.blank? r = ValidateEmail.valid?(value) # Check if domain has DNS MX record if r && options[:mx] require 'valid_email/mx_validator' r &&= MxValidator.new(:attributes => attributes).validate(record) elsif r && options[:mx_with_fallback] require 'valid_email/mx_with_fallback_validator' r &&= MxWithFallbackValidator.new(:attributes => attributes).validate(record) end # Check if domain is disposable if r && options[:ban_disposable_email] require 'valid_email/ban_disposable_email_validator' r &&= BanDisposableEmailValidator.new(:attributes => attributes).validate(record) end rescue Exception => e r = false end record.errors.add attribute, (options[:message] || I18n.t(:invalid, :scope => "valid_email.validations.email")) unless r end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
valid_email-0.0.8 | lib/valid_email/email_validator.rb |
valid_email-0.0.6 | lib/valid_email/email_validator.rb |
valid_email-0.0.7 | lib/valid_email/email_validator.rb |