Class: AttrValidator::Validators::EmailValidator
- Inherits:
-
Object
- Object
- AttrValidator::Validators::EmailValidator
- Defined in:
- lib/attr_validator/validators/email_validator.rb
Constant Summary collapse
- EMAIL_ADDRESS =
This rule was adapted from github.com/emmanuel/aequitas/blob/master/lib/aequitas/rule/format/email_address.rb
begin letter = 'a-zA-Z' digit = '0-9' atext = "[#{letter}#{digit}\!\#\$\%\&\'\*+\/\=\?\^\_\`\{\|\}\~\-]" dot_atom_text = "#{atext}+([.]#{atext}*)+" dot_atom = dot_atom_text no_ws_ctl = '\x01-\x08\x11\x12\x14-\x1f\x7f' qtext = "[^#{no_ws_ctl}\\x0d\\x22\\x5c]" # Non-whitespace, non-control character except for \ and " text = '[\x01-\x09\x11\x12\x14-\x7f]' quoted_pair = "(\\x5c#{text})" qcontent = "(?:#{qtext}|#{quoted_pair})" quoted_string = "[\"]#{qcontent}+[\"]" atom = "#{atext}+" word = "(?:#{atom}|#{quoted_string})" obs_local_part = "#{word}([.]#{word})*" local_part = "(?:#{dot_atom}|#{quoted_string}|#{obs_local_part})" dtext = "[#{no_ws_ctl}\\x21-\\x5a\\x5e-\\x7e]" dcontent = "(?:#{dtext}|#{quoted_pair})" domain_literal = "\\[#{dcontent}+\\]" obs_domain = "#{atom}([.]#{atom})+" domain = "(?:#{dot_atom}|#{domain_literal}|#{obs_domain})" addr_spec = "#{local_part}\@#{domain}" pattern = /\A#{addr_spec}\z/u end
Class Method Summary collapse
-
.validate(value, email_flag) ⇒ Array
Validates that value actually is email.
- .validate_options(email_flag) ⇒ Object
Class Method Details
.validate(value, email_flag) ⇒ Array
Validates that value actually is email
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/attr_validator/validators/email_validator.rb', line 32 def self.validate(value, email_flag) return [] if value.nil? errors = [] if email_flag errors << AttrValidator::I18n.t("errors.invalid_email") unless !!EMAIL_ADDRESS.match(value) else errors << AttrValidator::I18n.t("errors.can_not_be_email") if !!EMAIL_ADDRESS.match(value) end errors end |
.validate_options(email_flag) ⇒ Object
44 45 46 |
# File 'lib/attr_validator/validators/email_validator.rb', line 44 def self.(email_flag) AttrValidator::ArgsValidator.is_boolean!(email_flag, :validation_rule) end |