All posts tagged ‘email’

File Under: Programming

Four Regular Expressions to Check Email Addresses

How do you find out if a user has entered a valid email address? Do you check for an at-sign, or is it more complicated? For many developers the answer is a regular expression, a little bit of code that can describe text patterns using wildcards and other special characters. If you’re new to the topic, we have a great regular expression tutorial.

Here are four regular expressions (often called regexes) that all validate the format of an email address. They have increasing degrees of complexity. The more complicated, the more accurate each is at matching only email addresses.

1. Dirt-simple approach

Here’s a regex that only requires a very basic xxxx@yyyy.zzz:

.+\@.+\..+

Upside: Dirt simple.

Downside: Even invalid email addresses like xxxx@yyyy.zzz, or even a@b.c, make it through.

2. Slightly more strict (but still simple) approach

Regular-Expressions.Info provides a basic email validation regex that tries to be a little smarter:

[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}

Upside: Only allows email address-friendly characters, restricts domain extension to only two to four characters.

Downside: It still allows many invalid email addresses, and misses some longer domain extensions (.museum, for example).

3. Specify all the domain extensions approach

Reddit user teye points to his regex, which only allows domain extensions that actually exist:

([a-z0-9][-a-z0-9_\+\.]*[a-z0-9])@([a-z0-9][-a-z0-9\.]*[a-z0-9]\.(arpa|root|aero|biz|cat|com|coop|edu|gov|info|int|jobs|mil|mobi|museum|name|net|org|pro|tel|travel|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|([0-9]{1,3}\.{3}[0-9]{1,3}))

Upside: It doesn’t allow xxxx@yyyy.zzz!

Downside: Upkeep could be tough with this one. You’d have to update any time new domain extensions are announced. In fact, you already would need to add the .me extension.

4. Way complicated approach

A Perl module has a long regular expression based on the standard description of an email address. It’s so long (nearly 6,500 characters!) that I won’t include it here.

Upside: It’s complete.

Downside: It’s way complicated.

Meet in the middle approach

You’ll have to decide, if you haven’t already, which regular expression to use. Likely, you’ll choose somewhere in the middle of the examples we’ve given. Regular-Expressions.Info has a good run-down of the trade-offs of different approaches.

Have you already decided how to check email addresses? How do you do it?

[via Reddit]

See also:

File Under: Web Basics

The Safest Way to Publish Your Email Address

At the dawn of time, including your email address on a web page didn’t seem like a horrible idea. Now, that’s the easiest way to get on every spam list around. Sadly, this makes it a little more difficult to solicit email from site visitors.

Silvan Mühlemann decided to find the best way to safely publish an email address. He started his test almost two years ago and recently published the results.

Silvan created nine email addresses and use a different method of obfuscation–nine different ways of hiding the actual address. Of the methods he tested, three of the email addresses never received a spam message.

The simplest method is to add markup with display: none styling so it doesn’t show:

email@<span style="display: none">null</span>example.com

The other two methods are reversing backwards text with unicode declarations and simple ROT13 encoding using JavaScript to decode. Next on the list, receiving just a few spam emails, was the popular email AT example DOT com method. Silvan did not test the email-as-image method, one employed by Facebook on its profile pages.

These methods probably won’t work with a mailto: link for easy clicking. Still, they all allow copy-pasting, instead of laborious re-typing, so they’re worth a shot. And yes, I know you could just use a contact form, but isn’t that a little impersonal? I think so.

File Under: Software & Tools

Catch a Glimpse of Mozilla’s E-Mail Future in Thunderbird 3 Alpha 1

thunderbird3.jpg

It’s alive! Mozilla has released the first alpha version of its upcoming Thunderbird 3.0, the company’s next-generation e-mail application. We don’t suggest you rush out and download it unless you’re a true early adopter; this release isn’t stable and lacks many of the features planned for Thunderbird 3′s final release.

This alpha release is primarily intended to let Thunderbird fans know that the project is alive and well and the team is working hard on the next version of the open source e-mail client. It’s also the first product to emerge from the newest entity within the Mozilla organization, Mozilla Messaging. The company was spun off this past winter in order to give more attention to the Thunderbird project, which had long lived under the shadow of the much more successful Firefox browser.

The feature set looks promising. However, one the most anticipated features of Thunderbird 3 – integration with Lightning, an extension that adds calendar functionality – isn’t available yet.

Continue Reading “Catch a Glimpse of Mozilla’s E-Mail Future in Thunderbird 3 Alpha 1″ »

File Under: Software & Tools

Dreamhost Discontinues Procmail Support

DreamhostDreamhost hosts over half a million domains, luring customers with cheap rates and acres of storage and bandwidth. They’ve also been historically pretty good in terms of using open tools and standards. Amid tales of web hosts being miscellaneously annoying and prohibiting basic tools like ssh, Dreamhost always seemed like a decent option. (I myself have never been their customer.)

In January they lost a lot of friends when they mis-billed their customer base, then added insult to injury with an overly irreverent apology.

More upsetting to me is the host’s recent decision to make Procmail, the classic and powerful mail-filtering tool, unavailable to users, after providing it for years.

Continue Reading “Dreamhost Discontinues Procmail Support” »

File Under: Software & Tools

Yahoo Unlimited Mail Fills Up


The Wall Street Journal’s tech blog reports trouble with Yahoo mail. Namely, it seems that keeping several years’ worth of e-mail in a Yahoo “unlimited” inbox causes a nasty error and the vanishing of all that mail.

Thanks to the Journal’s high profile, a fix is now expected in “a month or so.”

Last I heard, which was not terribly recently, Yahoo was running a modified version of Qmail as their back-end. (Please correct me if there’s more recent information.)

Continue Reading “Yahoo Unlimited Mail Fills Up” »