0.0
No commit activity in last 3 years
No release in over 3 years
Validates the email format.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

> 1.10
>= 0
>= 0

Runtime

 Project Readme

Email Format

Build Status

This gem uses the thorough email validation implemented by the email_regex gem written by Doug Wiegley which "provides a valid email regex that conforms to most valid RFC edges cases (disallows backticks), and allows for a few illegal patterns that are in common use".

Installation

Add this line to your application's Gemfile:

gem 'email_format'

And then execute:

$ bundle

Or install it yourself as:

$ gem install email_format

Usage

EmailFormat Module

There's a valid? method in the EmailFormat module that accepts an email as an argument:

require 'email_format'
EmailFormat.valid?('invalid_email')   # => false
EmailFormat.valid?('valid@email.com') # => true

ActiveModel::Validations

Using it is as simple as using the validates keyword in your model:

class User < ActiveRecord::Base

  # ...

  validates :email, email_format: true

  # ...

end

Now the email attribute will be validated accordingly:

User.new('valid@email.com').valid? # => true
User.new('invalid_email@@').valid? # => false

By default, email_format is pretty relaxed, but there is a strict mode

class User < ActiveRecord::Base

  # ...

  validates :email, email_format: { strict: true }

  # ...

end

Also, the model in question doesn't need to inherit from ActiveRecord::Base, you only need to include ActiveModel::Validations in your class:

require 'email_format'

class Awesome
  include ActiveModel::Validations
  attr_accessor :email
  validates :email, email_format: true
end

awesome = Awesome.new

awesome.email = "valid@email.com"
awesome.valid? # => true

awesome.email = "invalid_email"
awesome.valid? # => false

Contributing

  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 new Pull Request