Community Patterns

Community Library Entry

2

Regular Expression
Created·2022-03-22 11:51
Flavor·PCRE2 (PHP)

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

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