email_validator ActiveModel::EachValidator
Validate e-mail addresses against RFC 2822 and RFC 3696.
Installation
gem 'vjt-email_validator', :git => 'git://github.com/vjt/email_validator'
Usage
Standalone:
EmailValidator.valid?(email) # => true or false
Inside an ActiveRecord model:
class Person < ActiveRecord::Base
validates :email, :email => true
end
Options
Giving ‘:email => true` to the `validate` method uses the following default options. Customize them using `:email => { .. }`; E.g. `:email => => true`
:message
String. A custom error message (default is: "does not appear to be a valid e-mail address")
:mx_message
String. A custom error message displayed when there is no MX for the given e-mail address
(default is: "is not routable")
:multiple_message
String. A custom error message displayed when one of the e-mail addresses in the record
is invalid (default is "appears to contain an invalid e-mail address)
:multiple
Boolean. Allows multiple email addresses separated by space and/or comma/colon
:check_mx
Boolean. Check domain for a valid MX record (default is false)
:local_length
Maximum number of characters allowed in the local part (default is 64)
:domain_length
Maximum number of characters allowed in the domain part (default is 255)
Testing
To execute the unit tests run rake test
.
The unit tests for this plugin use an in-memory sqlite3 database.
Resources
Original Credits
Written by Alex Dunae (dunae.ca), 2006-11.
Many thanks to the plugin’s recent contributors: github.com/alexdunae/validates_email_format_of/contributors
Thanks to Francis Hwang (fhwang.net/) at Diversion Media for creating the 1.1 update. Thanks to Travis Sinnott for creating the 1.3 update. Thanks to Denis Ahearn at Riverock Technologies (www.riverocktech.com/) for creating the 1.4 update. Thanks to George Anderson (github.com/george) and ‘history’ (github.com/history) for creating the 1.4.1 update.
Rewrite
Rewrote by Marcello Barnaba ([email protected]), 2011-02 as an ActiveModel::EachValidator