validates_email_address_of
This provides an email validator for ActiveRecord 3.
Installation
Add this line to your application's Gemfile:
gem 'validates_email_address_of'
And then execute:
$ bundle
Or install it yourself as:
$ gem install validates_email_address_of
Usage
Here is the quick and dirty way to include validates_email_address_of
class User < ActiveRecord::Base
attr_accessible :email, :password, :password_confirmation
has_secure_password
validates :email, :email_address => true
end
There are three separate validation tests that get more and more complete. Each test is independent of the others.
While all test are indepent if a lower level test fails it will skip the high level test. All test run by default.
Format
This is a basic RegEx validation and only checks that the email is in the correct format. You can enable or disable
by specifying the :format
option.
validates :email, :email_address => { :format => false }
MX
This test gets even more acurate than just checking the format. This checks that the domain has at least one
MX record attached to it. this can be disabled similarly to format, except with the :mx
option.
validates :email, :email_address => { :mx => false }
SMTP Address Verification
This is the ultimate test. This will actually contact the mail server and ask it to verify that the provided email
exists. While this guarentees the email will exist it is slow, due to the slow run we suggest only running this test
on create. This can be controlled with the :smtp
option.
validates :email, :email_address => { :smtp => flase }
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request