Skip to content
Opinionated email address validation for ActiveModels/ActiveRecord
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib Implement the old behavior with new syntax Jan 22, 2019
.gitignore Generated gem via Bundler Mar 7, 2015
.travis.yml Ensure we update Bundler to the newest version Aug 2, 2019 Update CHANGELOG Aug 19, 2019
Gemfile Automated Rubocop fixes Oct 17, 2015
LICENSE.txt Generated gem via Bundler Mar 7, 2015 Merge pull request #6 from substancelab/rules Jan 22, 2019
Rakefile Rake task to launch IRB console with gem loaded Mar 9, 2015
activemodel-email_address_validator.gemspec Update activemodel requirement from >= 4.0, < 6.0 to >= 4.0, < 7.0 Aug 19, 2019

Email Address Validator

ActiveModel-style email address format validator

Build Status Code Climate Coverage Status

Whenever I have wanted to validate an email address it has been because I wanted to be somewhat certain I can send an email to someone. Usually this happens as part of a signup procedure.

At this point I have pretty much one criteria:

  • Don't reject a valid email address realistically in use by a potential user. Err on the side of accepting too much.

Quite frankly, I don't care about the RFC at this point, neither does the user. I care that my users can enter their email address and get on with using my product. I appreciate it if the application catches any misspellings of their email addresses, though - this is the opportune moment for them to correct it.


  • Should not accept local email addresses: No user ever needed to sign up using "postmaster@localhost" or "bob@" even though they are perfectly valid email addresses.
  • Must work with I18n like Rails' built-in validators do. If not configured otherwise, the default translation key must be :invalid.

Usage examples

Simplest case

validates :email, :email_address => true

Bring your own regex

If you want to use a specific regular expression:

validates :email, :email_address => {:format => /.+@.+\..+/}

Bring your own logic

If a regular expression isn't enough for you, you can include your own rules for email addresses. For example, you could validate that all email adresses belong to the same company:

validates :email, :email_address => {
  :with => proc { |address| address.end_with?("") }

Verify domain (still to be done - pull request, anybody?)

This also checks that the domain actually has an MX record. Note this might take a while because of DNS lookups.

validates :email, :email_address => {:mx => true}


Add this line to your application's Gemfile:

gem 'activemodel-email_address_validator'

And then execute:

$ bundle

Or install it yourself as:

$ gem install activemodel-email_address_validator


Other libraries




  1. Fork it ( )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request
You can’t perform that action at this time.