Email Regular Expression

One of my colleagues asked a question that I’ve heard dozens of times over my career…

What’s a good regular expression for validating email addresses.

Sadly, due to poor standards, poor implementation choices, and just the sheer age of Email, this is a surprisingly tough problem.

The best way to validate an email address is to email it, and get the user to do something. That’s not really feasible if it’s someone just filling in a form.

Failing that, I came up with:

^[^@\s]+@[^@\s]+\.[^@\s]+$

This is the same as suggested by Microsoft, which is gratifying. You can see the logic of it here.

Advertisement
Email Regular Expression

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.