A few weeks ago I learned about a great Gmail fea­ture that allows you to fil­ter your email with per­son­al­ized email addresses using a plus sign. For exam­ple, if you think you’ll be spammed by sign­ing up for some­thing like a forum, you could sign up with the email username+forum@gmail.com and setup a fil­ter to auto­mat­i­cally mark those mes­sages as spam.

Both of my cur­rent projects at Sprout­box and the Epp­ley Insti­tute involve set­ting up or test­ing user sys­tems. To do this, I make a lot of dum­mie test accounts but these accounts need to have valid email addresses to test things like pass­word recov­ery. Instead of rack­ing my brain for every email address I have ever cre­ated, I started reg­is­ter­ing test accounts with emails such as username+tester1@gmail.com.

This was work­ing great until today in Joomla my email addresses weren’t val­i­dat­ing with their JavaScript val­i­da­tion script. Luck­ily, it was easy to see how they were val­i­dat­ing email addresses.

scrnr-validateInside the validate.js script was a small func­tion that used a reg­u­lar expres­sion to make sure entered email addresses were in the tra­di­tional form of Username09@Domain1.com.

[js]this.setHandler(‘email’,
func­tion (value) {
regex=/^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+.)+[a-zA-Z0-9.-]{2,4}$/;
return regex.test(value);
});[/js]

If you’ve never seen or used reg­u­lar expres­sions before, they are very pow­er­ful and awe­some but can be over­whelm­ing at first. All that expres­sion is say­ing — “Look at the begin­ning of the line and make sure there are only upper and low­er­case let­ters, num­bers zero though nine, peri­ods, under­scores, and dashes before at least one at sign.” The rest of it goes the same way.

So to allow plus signs in the first part of the email address you just add a ‘+’ after the ‘-’ and before the ’]’.

[js]regex=/^[a-zA-Z0-9._-+]+@([a-zA-Z0-9.-]+.)+[a-zA-Z0-9.-]{2,4}$/;[/js]

Now it will allow email addresses that look like Username90+whatever@Domain1.com.

If you’re a devel­oper and want to be nice to your users, make sure to remem­ber to add this ‘+’ in your form val­i­da­tion scripts so that soon-to-be Gmail nin­jas like me can fil­ter your spam newslet­ters accordingly.