class Walid::EmailValidator
Validate email adresses
Validate email addresses based on RFC5321 and RFC5322 (with updates)
Options:
-
quotes (default: false) - allow quotings in local part (i.e. lo.“lol”)
-
utf (default: false) - allow UTF-8 characters in address
-
ip (default: false) - allow IP addresses as domain part
Public Instance Methods
validate_each(record, attribute, value)
click to toggle source
# File lib/walid/email_validator.rb, line 12 def validate_each(record, attribute, value) @local, _, @domain = value.rpartition('@') record.errors.add(attribute, 'Invalid email format.') if check_local end
Private Instance Methods
check_local()
click to toggle source
# File lib/walid/email_validator.rb, line 20 def check_local @lparser ||= Parser::EmailLocalPart.new parsed = @lparser.parse(@local) parts = parsed.map(&:keys).unique !(options[:quotes] && parts.include?(:q)) rescue false end