GithubHelp home page GithubHelp logo

krzysztofjablonski / validates_email_format_of Goto Github PK

View Code? Open in Web Editor NEW

This project forked from validates-email-format-of/validates_email_format_of

1.0 1.0 0.0 858 KB

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

Home Page: http://code.dunae.ca/validates_email_format_of.html

License: MIT License

validates_email_format_of's Introduction

validates_email_format_of Gem and Rails Plugin

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

Installation

Installing as a gem:

gem install validates_email_format_of

Installing as a Ruby on Rails 2 plugin:

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

Or in your Rails 3 Gemfile

gem 'validates_email_format_of', :git => 'git://github.com/alexdunae/validates_email_format_of.git'

Usage

class Person < ActiveRecord::Base
  validates_email_format_of :email
end

# Rails 3
class Person < ActiveRecord::Base
  validates :email, :email_format => {:message => 'is not looking good'}
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.
:local_length
  Maximum number of characters allowed in the local part (default is 64)
:domain_length
  Maximum number of characters allowed in the domain part (default is 255)

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-11.

Many thanks to the plugin’s recent contributors: github.com/alexdunae/validates_email_format_of/contributors

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.

validates_email_format_of's People

Contributors

alexdunae avatar technicalpickles avatar mike-burns avatar history avatar unpublishedworks avatar henrik avatar lsegal avatar qrush avatar tomhughes avatar

Stargazers

Krzysztof Jablonski avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.