Aaron Longnion asked if I could modify the email validation on my blog to allow the + character in email addresses. Apparently in gmail you can add +anything to your email address (after the username and before the @ character) and it will still arrive in your account. This helps people organize emails that come from filling out online forms, or signing up for newsletters, or commenting on blogs or whatever. I went ahead and modified the isEmail function that BlogCFC uses to accommodate this, and then thought I would share it with the world just in case someone asks you fix your blog too.

All you have to do is modify the /includes/udf.cfm file and change the IsEmail UDF that is defined there to this:

<cfscript>
function IsEmail(str) {
//supports new top level tlds
if (REFindNoCase("^['_a-z0-9-]+(.['_a-z0-9-]+)*(+['_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*.(([a-z]{2,3})|(aero|coop|info|museum|name))$",str)) return TRUE;
   else return FALSE;
}
</cfscript>

There are probably a bazillion other posts out there with regular expressions that will show you how to do this, but I don't get that many chances to exercise my RegEx skills so I decided to modify this one myself for the 5 minutes of practice. If you think there is a better way to write the expression then the way I did it then please leave me a comment.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
James Moberg's Gravatar What happens to regular expression email validation when domain names like "arstechnica.awesome" or "google.thegoogle" become mainstream?
http://arstechnica.com/news.ars/post/20080626-conf...
# Posted By James Moberg | 6/26/08 5:58 PM
Scott Bennett's Gravatar I don't see a lot of people forking out the 100k to 500k money to create a TLD like .awesome, but I was reading about that earlier today. I am not sure what all the rules are for what characters will be allowed or how long the TLD string can be, but it my best guess is the RegEx would be something like:

^['_a-z0-9-]+(.['_a-z0-9-]+)*(+['_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*.([a-z0-9-]+)$
# Posted By Scott Bennett | 6/26/08 6:26 PM
Dave Shuck's Gravatar I have modified all my email validation to allow plus signs, but I make use of ColdFusion's IsValid method.

Something like:
IsValid("Email",Replace(EmailAddress),"+",""))

It isn't nearly as impressive to look at as the regex example, but I am not sure that it is any less effective! :)
# Posted By Dave Shuck | 6/26/08 6:39 PM
Scott Bennett's Gravatar @Dave.

That would probably work for the most part, but what if someone puts a + in a part of the email address where it doesn't belong, that will pass your validation too like:

[email protected]
or
comment.spammer@fake+domain.com

The RegEx gives you a little more sophistication, and you get to feel smart because you can understand all that goblie-gook.
# Posted By Scott Bennett | 6/26/08 7:09 PM
Raymond Camden's Gravatar Thanks for doing this. I've added it to the 5.9.1 release.
# Posted By Raymond Camden | 7/29/08 2:59 PM
mirc's Gravatar thanks you.
# Posted By mirc | 11/24/08 8:22 AM
Jayne's Gravatar This was just what I was looking for, great resource. Bookmarked. http://www.sharevouchers.co.uk/2009/05/18/vistapri...
# Posted By Jayne | 5/19/09 12:21 AM