class Incline::EmailValidator

Validates a string to ensure it contains a valid email address.

validates :email_address, 'incline/email' => true

Constants

INTERNAL_DOM_REGEX
VALID_DOMAIN_REGEX

This regular expression should validate any domain.

VALID_EMAIL_REGEX

This regular expression should validate 99.9% of common email addresses.

There are some weird rules that it doesn't account for, but they should be rare.

Public Class Methods

valid?(email) click to toggle source

Validates that an email address is valid based on format.

# File lib/incline/validators/email_validator.rb, line 37
def self.valid?(email)
  return false if email.blank?
  !!(email =~ VALID_EMAIL_REGEX)
end

Public Instance Methods

validate_each(record, attribute, value) click to toggle source

Validates attributes to determine if they contain valid email addresses.

Does not perform an in depth check, but does verify that the format is valid.

# File lib/incline/validators/email_validator.rb, line 29
def validate_each(record, attribute, value)
  unless value.blank?
    record.errors[attribute] << (options[:message] || 'is not a valid email address') unless value =~ VALID_EMAIL_REGEX
  end
end