var emailAddressRE = regexp.MustCompile(`^(?i)(?:(?:\"[^\"]+\")|[a-z0-9!#$%&'*+\-\/=?^_` + "`" + `{|}~]+(?:\.[a-z0-9!#$%&'*+\-\/=?^_` + "`" + `{|}~]+)*)@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$`)
if !emailAddressRE.MatchString("[email protected]") {
panic("oops")
}
^(?i)(?:(?:\"[^\"]+\")|[a-z0-9!#$%&'*+\-\/=?^_`{|}~]+(?:\.[a-z0-9!#$%&'*+\-\/=?^_`{|}~]+)*)@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$
/^(?:(?:\"[^\"]+\")|[a-z0-9!#$%&'*+\-\/=?^_`{|}~]+(?:\.[a-z0-9!#$%&'*+\-\/=?^_`{|}~]+)*)@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i
^(?i)(?:(?:""[^""]+"")|[a-z0-9!#$%&'*+\-\/=?^_`{|}~]+(?:\.[a-z0-9!#$%&'*+\-\/=?^_`{|}~]+)*)@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$
Seems to validate in basically all typical situations, but it won't validate emojis even when they're valid. See below for examples.
β [email protected] (RHS starts with period)
β [email protected]. (RHS ends with period)
β [email protected] (RHS has two consecutive periods)
β emmaly@[email protected] (address contains two at-symbols)
β [email protected] (LHS starts with period)
β [email protected] (LHS ends with period)
β emmaly@@example.com (address contains two at-symbols)
β
"emmaly."@example.com (quoted LHS is valid)
β
".emmaly"@example.com (quoted LHS is valid)
β
"emmaly@"@example.com (quoted LHS is valid)
β
[email protected] (valid)
β
[email protected] (valid)
β
[email protected] (valid)
β
[email protected] (valid, though no TLDs are 1-character long)
β
[email protected] (valid)
β emmaly@π.tld (but emoji domains are technically valid)
β
[email protected] (punycode version of emoji domain is valid)
β π@example.com (non-ASCII on LHS unless quoted is technically invalid)
(but I think we should consider treating it as valid...)
β
"π"@example.com (quoted LHS validly contains non-ASCII)