Categories
Posts

Comparing E-mail Address Validating Regular Expressions

Validating an email address with a regular expression is something nearly every developer struggles with. So when I came across Comparing E-mail Address Validating Regular Expressions I wanted to make sure I left myself a note here so that I could find it again later 🙂

Several expressions were collected and run over an array of email string tests, so far this one has come out on top:

/^([w!#$%&’*+-/=?^`{|}~]+.)*[w!#$%&’*+-/=?^`{|}~]+@((((([a-z0-9]{1}[a-z0-9-]{0,62}[a-z0-9]{1})|[a-z]).)+[a-z]{2,6})|(d{1,3}.){3}d{1,3}(:d{1,5})?)$/i

Keep in mind that no regular expression can verify that an email address is actually legitimate, the only real test is to actually talk to the SMTP server responsible for that domain’s email and make sure it will accept it.

Leave a Reply

Your email address will not be published. Required fields are marked *