Regular Expressions 101

Community Patterns

Community Library Entry

2

Regular Expression
PCRE2 (PHP >=7.3)

/
^(?!\.)(?:\.?[\w\+]++)++@(?!\.)(?:\.?(?:xn--)?(?!-|.*--)[a-zA-Z0-9\-]++(?<!-)){2,}$
/
img

Description

Intentionally leaves out weird stuff such as IPV4 or IPV6 for the domain part and quoted usernames with invalid chars in the addressee part. Handles internationalized domains with soft validation (only structural matching) and blocks domain parts starting or ending with dashes or containing double dashes (except in xn-- internationalization prefix).

Submitted by Victor Schröder - 3 years ago