Sunday, November 7, 2010

Plus sign in email address

I ordered a micro sd memory card from a random Finnish webstore today. The website appeared to have emerged via time machine from the mid 90s. However I have to give them credit. They did not try to be too clever and validate (incorrectly) my email address in their web form. They allowed a plus sign in the email address.

The plus sign is a very handy tool in organizing/labeling email automatically. Anything after the plus sign is ignored by email servers. Thus it can be used as a label. For example, if I order something from Amazon, I use an address like me+amazon@example.com. In my email client, I can then recognize anything that has amazon as the label and do what ever organizing I want automatically.

So good job, you, the webstore from the mid 90s! Many, many others do it wrong. The programmer's lesson is this. Do not try to validate an email address yourself. If you really need to validate it, use a library that does it right. Often the best way to validate an address is to send mail to it.