Class: EmailFormatValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/email_format_validator.rb

Defined Under Namespace

Modules: Patterns

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



23
24
25
26
27
28
# File 'lib/email_format_validator.rb', line 23

def validate_each(record, attribute, value)
  pattern_choosed = options[:rfc] ? Patterns::EMAIL : Patterns::LESS_RFC_COMPLIANT_EMAIL
  unless value =~ pattern_choosed
    record.errors.add(attribute, options[:message] || invalid_message(record, attribute))
  end
end