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:
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.
http://arstechnica.com/news.ars/post/20080626-conf...
^['_a-z0-9-]+(.['_a-z0-9-]+)*(+['_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*.([a-z0-9-]+)$
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! :)
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.