Regular Expressions 101

Community Patterns

Email address supporting plus addressing and multiple subdomains.

0

Regular Expression
ECMAScript (JavaScript)

/
^[a-z0-9]+([+._-][a-z0-9]+)*@([a-z0-9]+\.[a-z0-9]+[a-z0-9])$
/
i

Description

This expression follows the rules displayed at https://knowledge.validity.com/hc/en-us/articles/220560587-What-are-the-rules-for-email-address-syntax-. Note that their rules DO NOT exactly match those of the applicable RFC 5322 (sections 3.2.3 and 3.4.1) and RFC 5321, but rather supports a pattern which is more commonly accepted by the majority of servers which also support plus addressing. Note also that since this expression is attempting to test the allowances of multiple expression segments, it is not possible to enforce maximum address length specifications. For this reason, you should use a 2-pass verification method, with the first pass being the length tests (to improve efficiency). An example of that first pass is as follows: /^[a-z0-9+.-_]{1,64}@[a-z0-9.-_]{3,253}$/

I hope this help some of you!

Submitted by Eric Bewley - a year ago