Fat Fingers (a regex for fixing typoed e-mail addresses)
Hot diggity! I’ve found this to be so useful, I decided to turn the code into a Ruby Gem. You can find it over at rubygems.org/gems/fat_fingers. And if you want to fork / improve the code / tests, it’s over at GitHub.
This is about a regex I wrote for fixing e-mail typos. (When “firstname.lastname@example.org” enters in “email@example.com”, fix it for him.) You can see it here: fat_fingers.rb.
Let’s help our users!
Just a few minutes ago, I got a “message failed to deliver” e-mail. Why? The user had entered in their e-mail address incorrectly. firstname.lastname@example.org (note the lack of an “o” in “.cm”). So, now there’s a bit of a hassle, where I have to fix their e-mail in the system, then re-initiate whatever process sent them that e-mail.
That’s needless work.
Fat Fingers is simply a Ruby method for cleaning up e-mail typos.
It extends String objects with a method called
All you need to do is attach that method to the user’s e-mail address before you save them in the system. Like
There are some more instructions in the file itself, but it’s really straightforward.
So this isn’t a library / plugin?
Nope! It’s just a regex. Eight lines of code, and we tell you where you can stick ’em!
Aren’t we disenfranchising users with this?
There’s a similar tool, called Mailcheck.js. It offers suggestions to the user, to check the e-mail they entered to make sure it’s legit.
Fat Fingers is different, in that it does the work silently, without checking with the user.
Perhaps you want to roll with their approach. That’s cool, and you’d be in good company. For my own projects, I’d rather not bother the user with something that’s obviously wrong, if I can fix it on my own.
A quick note for users running this on Ruby < 1.9
Our multi-line chaining in this regex features the dots at the beginning of each line. Just move them to the end of the previous line if you’re on Ruby 1.8.x.
Fat Fingers has its own tests.
Once you’ve cloned it to your system, just run
ruby fat_fingers.rb and you’ll see the output of the tests. Unless something’s gone horribly wrong, they should all pass.
Make it better!
I’d love to hear suggestions, critiques, and improvements. Feel free to fork it, ask me to pull in changes, and so on. I’d also love any test improvements.