Class: ParanoidStarlight::Validators::EmailValidator

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

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/paranoid_starlight.rb', line 12

def validate_each(record, attribute, value)
  # username in email may have @ in string
  # username should be case sensitive, domain is not
  unless value =~ %r{\A([^\s]+)@((?:[-a-zA-Z0-9]+\.)+[a-zA-Z]{2,})\z}
    record.errors[attribute] << (options[:message] || 'is not an email')
  end
end