Email Repair is a utility for sanitizing and validating user-provided email address.
Add this line to your application's Gemfile:
gem 'email_repair'
And then execute:
$ bundle
Or install it yourself as:
$ gem install email_repair
require 'email_repair'
require 'ostruct'
EmailRepair::Mechanic.new.repair('blah@gmail')
# "blah@gmail.com"
EmailRepair::Mechanic.new.repair_all(%w[One@@two.com bleep@blop plooooooop])
# <OpenStruct sanitized_emails=["one@two.com"], invalid_emails=["bleep@blop", "plooooooop"]>
Takes a single email address, applies the available repairs to it and returns
the repaired email. If the email cannot be repaired, nil
is returned instead.
Takes an array of emails, applies available repairs to each email and returns an
OpenStruct
containing keys sanitized_emails:
with a unique array of the
emails that were able to be repaired, and invalid_emails:
with unique array of
the emails that were unable to be repaired
Returns a regular expression to be used to validate user-supplied email addresses.
Repairs common email typos:
- downcases the email
- removes white space
- removes duplicate @ symbols
- replaces
.c0m
with.com
- replaces commas with periods
Adds missing top-level domain for common email domains. For example, it replaces
blah@gmail
with blah@gmail.com
.
Adds missing period between the domain and top-level domain for common email
domains. For example, it replaces blah@gmailcom
with blah@gmail.com
.
Replaces '#', '.', or '-', with '@', or adds missing @ symbol for common
domains. For example, it replaces blahgmail.com
and blah#gmail.com
with
blah@gmail.com
.
Fixes swapped letters ('ia' instead of 'ai') in common domains. For example, it
replaces blah@gmial.com
with blah@gmail.com
.
Extracts the email address from strings that contain other text. For example, it
replaces blah <blah@email.com>
with blah@email.com
.
- Fork it ( https://github.com/[my-github-username]/email_repair/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request