EmailInquire is a library to validate email for common typos and one-time email providers.
Before an user is an user, it's a visitor. And he must register to be so. What if he makes a typo while entering its email address during the registration ? If he didn't notice, you just lost him. He won't be able to sign in next time.
Your users :
- may not be as tech saavy as you;
- may not remember exactly their email address;
- may make a typo while typing their email address (very very common on a mobile keyboard).
While we can't do so much for the name part of the email address, for the domain part, we can be smart!
And also, we don't want for users to use one-time email addresses (also called burner email addresses).
One char typo for 43 common email providers of France, United Kingdom and USA:
gmil.com
=> hintgmail.com
hitmail.com
=> hinthotmail.com
outloo.com
=> hintoutlook.com
virinmedia.com
=> hintvirginmedia.com
- ...
United Kingdom .xx.uk
domains:
foo.couk
=> hintfoo.co.uk
fooco.uk
=> hintfoo.co.uk
foo.uk
=> hintfoo.co.uk
foo.judiciary.uk
=> ok!- ...
Providers with an unique domain:
gmail.fr
=> hintgmail.com
gmail.de
=> hintgmail.com
google.com
=> hintgmail.com
free.com
=> hintfree.fr
laposte.com
=> hintlaposte.net
laposte.fr
=> hintlaposte.net
- ...
1375 one-time email providers (a.k.a. burners, source):
yopmail.com
=> invalid- ...
Add this line to your application's Gemfile:
gem 'email_inquire'
And then execute:
$ bundle
Or install it yourself as:
$ gem install email_inquire
Use EmailInquire.validate(email)
, you'll get a EmailInquire::Response
that represents weither
or not the email address is valid or may contain a mistake.
Methods of EmailInquire::Response
:
Method | Description | Possible values |
---|---|---|
#email |
The validated email address | "john.doe@gnail.com" |
#status |
The status of the validation | :valid :invalid or :hint |
#valid? |
Is the email valid ? | true or false |
#invalid? |
Is the email invalid ? | true or false |
#hint? |
Is there a possible mistake and you have to show a hint to the user ? | true or false |
#replacement |
A proposal replacement email address for when status is :hint |
"john.doe@gmail.com" or nil |
A valid case:
response = EmailInquire.validate("john.doe@gmail.com")
response.status # :valid
response.valid? # true
An invalid case:
response = EmailInquire.validate("john.doe@yopmail.com")
response.status # :invalid
response.valid? # false
response.invalid? # true
A hint case:
response = EmailInquire.validate("john.doe@gmail.co")
response.status # :hint
response.valid? # false
response.hint? # true
response.replacement # "john.doe@gmail.com"
I think it's important to just offer a hint to the user and to not automatically replace the maybe faulty email address in the form.
A "Did you mean xxx@yyy.zzz ?" has the following advantages:
- user remains in charge: we could have hinted against a perfectly valid email;
- user is educated;
- mini whaoo effect;
This "Did you mean xxx@yyy.zzz ?" is better being actionable, and appearing to be so: a click or tap on it should replace the email by the suggestion.
+---------------------------------------+ +---------+
| john.doe@yaho.com | | Sign Up |
+---------------------------------------+ +---------+
Did you mean john.doe@yahoo.com ?
Note that you could even have this validation for your Sign In form...
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/maximeg/email_inquire.
The gem is available as open source under the terms of the MIT License.