Sha256: 89152c5eca36737aac364916f79c8b951b3b695c3cccc0687a026105edeb74b7
Contents?: true
Size: 620 Bytes
Versions: 1
Compression:
Stored size: 620 Bytes
Contents
module MailValidation class EmailValidator < ActiveModel::EachValidator #uses the mail gem to validate an email address #also requires that the email is present and includes a domain def validate_each(record, attribute, value) begin address = Mail::Address.new(value) if address.domain.nil? append_error(record, attribute) end rescue Mail::Field::ParseError => e append_error(record, attribute) end end protected def append_error(record, attribute) record.errors.add(attribute, options[:message] || :invalid) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mail_validation-0.0.1 | lib/mail_validation/email_validator.rb |