Reject junk email addresses with email veracity

Posted by glenn on Tuesday, November 20, 2007

Posted in ruby on rails, email, data validation

validate_email_addresses

Carsten Nielsen has created an amazing plugin for rails called email veracity. It takes all of the heavy lifting out of what can often be a problematic part of data validation, and takes it a step further than most.

Not only does email veracity remove the need for a convoluted regexp to match against the email string, but it will also check the domain records to ensure that the MX entry is currently accepting mail, wow!

So how do I check the format of an email address?

Add this to the code on your model definition:

validates_email_veracity_of :email

that single line does the domain check too! You can turn it off, apply a timeout, and/or a custom error message if you like too:

validates_email_veracity_of :email, :domain_check => false, :timeout => 5, :message => "is not valid"

Installation

It’s available as a plugin so use piston, or the following command:

script/plugin install http://svn.savvica.com/public/plugins/validates_email_veracity_of
Glenn Gillen is a ruby, merb, and ruby on rails developer with clients in London, New York, Los Angeles, and Australia. Contact Ruby Pond if you wish to discuss hiring Glenn or one of our other developers for your own project.
blog comments powered by Disqus