<commit_before># Purpose

It validates email for application use (registering a new account for example)

# Usage

In your Gemfile :

    gem 'valid_email'


In your code :

    require 'valid_email'
    class Person
      include ActiveModel::Validations
      attr_accessor :name, :email

      validates :name, :presence => true, :length => { :maximum => 100 }
      validates :email, :presence => true, :email => true
    end


    p = Person.new
    p.name = "hallelujah"
    p.email = "<EMAIL>"
    p.valid? # => true

    p.email = "<EMAIL>"
    p.valid? # => false

    p.email = "<NAME> <<EMAIL>>"
    p.valid? # => false

You can check if email domain has MX record :

    validates :email, :email => {:mx => true, :message => I18n.t('validations.errors.models.user.invalid_email')}

Or

    validates :email, :email => {:message => I18n.t('validations.errors.models.user.invalid_email')}, :mx => {:message => I18n.t('validations.errors.models.user.invalid_mx')}

Alternatively, you can check if an email domain has a MX or A record by using `:mx_with_fallback` instead of `:mx`.

You can detect disposable accounts

    validates :email, :email => {:ban_disposable_email => true, :message => I18n.t('validations.errors.models.user.invalid_email')}
<commit_msg>Add domain check to README<commit_after># Purpose

It validates email for application use (registering a new account for example)

# Usage

In your Gemfile :

    gem 'valid_email'


In your code :

    require 'valid_email'
    class Person
      include ActiveModel::Validations
      attr_accessor :name, :email

      validates :name, :presence => true, :length => { :maximum => 100 }
      validates :email, :presence => true, :email => true
    end


    p = Person.new
    p.name = "hallelujah"
    p.email = "<EMAIL>"
    p.valid? # => true

    p.email = "<EMAIL>"
    p.valid? # => false

    p.email = "<NAME> <<EMAIL>>"
    p.valid? # => false

You can check if email domain has MX record:

    validates :email, :email => {:mx => true, :message => I18n.t('validations.errors.models.user.invalid_email')}

Or

    validates :email, :email => {:message => I18n.t('validations.errors.models.user.invalid_email')}, :mx => {:message => I18n.t('validations.errors.models.user.invalid_mx')}

You can check if the email domain looks valid. This uses a regular expression so no external services are required, which improves the performance of this check:

    validates :email, :email => {:domain => true}

Alternatively, you can check if an email domain has a MX or A record by using `:mx_with_fallback` instead of `:mx`.

You can detect disposable accounts

    validates :email, :email => {:ban_disposable_email => true, :message => I18n.t('validations.errors.models.user.invalid_email')}

{'fraction_non_alphanumeric': 0.13186416184971098, 'fraction_numerical': 0.007947976878612716, 'mean_word_length': 3.5171288743882543, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4053973', 'n_tokens_mistral': 924, 'n_tokens_neox': 856, 'n_words': 276}