alexdunae / validates_email_format_of

Validate e-mail addreses against RFC 2822 and RFC 3696 with this popular Ruby on Rails plugin and gem.

This URL has Read+Write access

name age message
file .gitignore Sat Jan 03 11:10:36 -0800 2009 Updated .gitignore [alexdunae]
file CHANGELOG.rdoc Tue Nov 17 21:46:16 -0800 2009 Documentation updates [alexdunae]
file MIT-LICENSE Wed Dec 31 11:30:45 -0800 2008 Updated docs for github [alexdunae]
file README.rdoc Tue Nov 17 21:46:16 -0800 2009 Documentation updates [alexdunae]
file init.rb Thu Nov 20 15:50:23 -0800 2008 Added Travis Sinnott's patch to check for MX re... [alexdunae]
directory lib/ Tue Nov 17 21:42:48 -0800 2009 Disallowed underscores in the domain name [alexdunae]
directory rails/ Wed Dec 31 11:30:45 -0800 2008 Updated docs for github [alexdunae]
file rakefile.rb Wed Dec 31 11:30:45 -0800 2008 Updated docs for github [alexdunae]
directory test/ Tue Nov 17 21:42:48 -0800 2009 Disallowed underscores in the domain name [alexdunae]
file validates_email_format_of.gemspec Tue Nov 17 21:46:16 -0800 2009 Documentation updates [alexdunae]
README.rdoc

validates_email_format_of Gem and Rails Plugin

Validate e-mail addresses against RFC 2822 and RFC 3696.

Installation

Installing as a gem:

  gem sources -a http://gems.github.com
  gem install alexdunae-validates_email_format_of

Installing as a Ruby on Rails plugin:

  ./script/plugin install http://github.com/alexdunae/validates_email_format_of.git

Usage

 class Person < ActiveRecord::Base
   validates_email_format_of :email
 end

As of version 1.4, it’s possible to run e-mail validation tests (including MX checks) without using ActiveRecord or even touching a database. The validate_email_format method will return nil on a valid e-mail address or an array of error messages for invalid addresses.

  results = ValidatesEmailFormatOf::validate_email_format(email, options)

  if results.nil?
    # success!
  else
    puts results.join(', ')
  end

Options

  :message
     String. A custom error message (default is: " does not appear to be a valid e-mail address")
  :on
     Symbol. Specifies when this validation is active (default is :save, other options :create, :update)
  :allow_nil
     Boolean. Allow nil values (default is false)
  :allow_blank
     Boolean. Allow blank values (default is false)
  :check_mx
     Boolean. Check domain for a valid MX record (default is false)
  :if
     Specifies a method, proc or string to call to determine if the validation should occur
     (e.g. :if => :allow_validation, or :if => Proc.new { |user| user.signup_step > 2 }). The method,
     proc or string should return or evaluate to a true or false value.
  :unless
     See :if option.

Testing

To execute the unit tests run rake test.

The unit tests for this plugin use an in-memory sqlite3 database.

Resources

Credits

Written by Alex Dunae (dunae.ca), 2006-09.

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.