How to match emails?

Validating email addresses can be a pain in the butt. At the end of the day, the only way to ensure an email address is valid 100% of the time is to send them a confirmation email… So you should do this. That being said, doing some basic email validation with regular expressions is a good move for things like client-side error checking.

For more glorious detail on email validation with regex, see this StackOverflow.

The Most Basic

This verifies that there is an @ symbol with something before it… This is my favorite. Regex: ^.+@.+$

W3C’s Email Regex

This is the regex used by the W3C when you create an email input:

<input type="email" placeholder="Enter your email" />

Regex: ^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$



×

Subscribe

The latest tutorials sent straight to your inbox.