Updating EmailVeracity to allow single character email addresses

I got a request from WineAlign today to allow a user to register with an email address with only one character in the name like “m@wibblz.com”.  Now I’m going to admit, I haven’t tested using just one character before.  Sure enough it was failing.  I am using the EmailVeracity gem to validate my mail which is working pretty well and it is very easy to tweak to your needs.  First I located the problem, it was the regex that was validating the format of the email address.  I took the following regex

/\A(([\w]+[\w\+_\-\.]+[\+_\-\.]{0})@((?:[-a-z0-9]+\.)+[a-z]{2,})){1}\Z/i

over to rubular.com and started testing.  It was a quick tweak to the regex and I ended up with this.

/\A(([\w]+[\w\+_\-\.]*[\+_\-\.]{0})@((?:[-a-z0-9]+\.)+[a-z]{2,})){1}\Z/i

All I needed to do was then update the gem itself.  Easy!  In a config initializer throw in this one line and restart!

EmailVeracity::Config[:valid_pattern] = /\A(([\w]+[\w\+_\-\.]*[\+_\-\.]{0})@((?:[-a-z0-9]+\.)+[a-z]{2,})){1}\Z/i

Great!!  WineAlign is now accepting email address like “m@wibblz.com”

Thursday, July 23rd, 2009 Uncategorized

2 Comments to Updating EmailVeracity to allow single character email addresses

  • Nathan, thanks for finding this, I was going to use your pattern as the new default, but it fails some of the existing tests. Anyways it’s fixed now for everyone and on GitHub.

    http://github.com/heycarsten/email-veracity

  • nate says:

    Hey, thanks for updating it for everyone Carsten.

  • Leave a Reply