Need help with validates_email_format_of?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

validates-email-format-of
365 Stars 81 Forks MIT License 206 Commits 28 Opened issues

Description

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

Services available

!
?

Need anything else?

Contributors list

= validatesemailformat_of Gem and Rails Plugin

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

== Installation

Installing as a gem:

gem install validatesemailformat_of

Or in your Gemfile:

gem 'validatesemailformat_of'

== Usage

# Rails # I18n locales are loaded automatically. class Person < ActiveRecord::Base validatesemailformatof :email, :message => 'is not looking good' # OR validates :email, :emailformat => { :message => 'is not looking good' } end

# Now you can test your model using RSpec: require "validatesemailformatof/rspecmatcher" describe Person do it { should validateemailformatof(:email).withmessage('is not looking good') } end

# If you're not using Rails (which really means, if you're not using ActiveModel::Validations) ValidatesEmailFormatOf::loadi18nlocales # Optional, if you want error messages to be in your language I18n.locale = :pl # If, for example, you want Polish error messages. ValidatesEmailFormatOf::validateemailformat("[email protected]") # => nil ValidatesEmailFormatOf::validateemailformat("invalidbecausethereisnoatsymbol") # => ["does not appear to be a valid e-mail address"]

=== Options

:message String. A custom error message when the email format is invalid (default is: "does not appear to be a valid e-mail address") :checkmx Boolean. Check domain for a valid MX record (default is false) :mxmessage String. A custom error message when the domain does not match a valid MX record (default is: "is not routable"). Ignored unless :checkmx option is true. :locallength Maximum number of characters allowed in the local part (everything before the '@') (default is 64) :domainlength Maximum number of characters allowed in the domain part (everything after the '@') (default is 255) :generatemessage Boolean. Return the I18n key of the error message instead of the error message itself (default is false) :with Specify a custom Regex as the valid email format. :on, :if, :unless, :allownil, :allowblank, :strict Standard ActiveModel validation options. These work in the ActiveModel/ActiveRecord/Rails syntax only. See http://api.rubyonrails.org/classes/ActiveModel/Validations/ClassMethods.html#method-i-validates for details.

== Testing

To execute the unit tests run rspec.

Tested in Ruby 1.8.7, 1.9.2, 1.9.3, 2.0.0, 2.1.2, JRuby and REE 1.8.7.

== Contributing

If you think we're letting some rules about valid email formats slip through the cracks, don't just update the Regex. Instead, add a failing test, and demonstrate that the described email address should be treated differently. A link to an appropriate RFC is the best way to do this. Then change the gem code to make the test pass.

describe "ithinkthisisnota[email protected]emailaddre.ss" do # According to http://..., this email address IS NOT valid. it { should haveerrorsonemail.because("does not appear to be valid") } end describe "ithinkthisisa[email protected]emailaddre.ss" do # According to http://..., this email address IS valid. it { shouldnot haveerrorsonemail } end

Yes, our Rspec syntax is that simple!

== Homepage

  • https://github.com/validates-email-format-of/validatesemailformat_of

== Credits

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

Many thanks to the plugin's recent contributors: https://github.com/alexdunae/validatesemailformat_of/contributors

Thanks to Francis Hwang (http://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 (http://www.riverocktech.com/) for creating the 1.4 update.

Thanks to George Anderson (http://github.com/george) and 'history' (http://github.com/history) for creating the 1.4.1 update.

Thanks to Isaac Betesh (https://github.com/betesh) for converting tests to Rspec and refactoring for version 1.6.0.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.