Archive for July, 2009
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”
