GithubHelp home page GithubHelp logo

anandvc / email_check Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dapatil/email_check

0.0 2.0 0.0 49 KB

ActiveModel email validator. Checks MX records. Ships with lists of free & disposable email providers that you may want to block

License: MIT License

Ruby 99.15% Shell 0.85%

email_check's Introduction

EmailCheck

Gem Version Build Status Dependency Status Code Climate Coverage Status

Description

This was originally built for Anonybuzz and is now used at StarTalent. This gem provides a robust mechanism to validate email addresses and restrict account creation to corporate email accounts.

This gem also ships with a data-set of free and disposable email domains which are used for validation checks.

You can also block certain usernames from creating accounts. Examples: admin, root

Validation mechanisms

  • Uses the mail gem.
  • Checks the domain's MX record
  • Validate against a blacklist of domains
  • Validates against a list of free email providers
  • Validates against a list of disposable email providers
  • A whitelist can be used to override these checks

Installation

Add this line to your application's Gemfile:

gem "check_email"

Usage

Use with ActiveModel

To validate just the format of the email address

class User < ActiveRecord::Base
  validates_email :email
end

To validate that the domain has a MX record:

validates_email :email, check_mx: true

To validate that the email is not from a disposable or free email provider:

validates_email :email, not_disposable:true, not_free:true

To validate that the domain is not blacklisted:

validates_email :email, not_blacklisted:true

To validate that the username is not blocked

validates_email :email, block_special_usernames:true

Everything together:

validates_email :email,
    check_mx: true, 
    not_disposable:true, 
    not_free:true, 
    not_blacklisted:true,
    block_special_usernames:true,
    message: "Please register with your corporate email"

To turn everything on by default, you can use the validates_email_strictness helper.

# Example above
validates_email_strictness :email

# Everything but allow free emails. This is what most people would want to use
validates_email_strictness :email, not_free:false

Modifying the inbuilt lists

The lists are exposed as assignable arrays so you can customize them or load whatever data you please.

Add a config/intializers/email_check.rb

# Set disposable email domains
EmailCheck.disposable_email_domains = ['freemail.org']
# Append to the whitelist
EmailCheck.whitelisted_domains << 'gmail.com'
EmailCheck.free_email_domains << 'thenewgmail.com'
# Setting a domain in the blacklist will also blacklist all subdomains
EmailCheck.blacklisted_domains << 'lvh.me'
# Block the 'anonymous' username for all domains
EmailCheck.blocked_usernames << 'anonymous'

Requirements

This gem is tested with Rails 4.0+. Ruby versions tested:

  • Ruby 2.0
  • Ruby 2.1
  • Ruby 2.2
  • Ruby 2.3

Rails versions tested: Rails 4.0 Rails 5.0

Credits

Contributing

  1. Fork it ( https://github.com/dapatil/email_check/fork )
  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 a new Pull Request

email_check's People

Contributors

dapatil avatar ghanti avatar kolomeetz avatar

Watchers

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