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("emmaly@example.com") {
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.
β emmaly@.example.com (RHS starts with period)
β emmaly@example.com. (RHS ends with period)
β emmaly@example..com (RHS has two consecutive periods)
β emmaly@e@xample.com (address contains two at-symbols)
β .emmaly@example.com (LHS starts with period)
β emmaly.@example.com (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)
β
emmaly@example.io (valid)
β
emma.ly@example.com (valid)
β
emmaly@example.com (valid)
β
emmaly@example.co.m (valid, though no TLDs are 1-character long)
β
emmaly@exa.mple.com (valid)
β emmaly@π.tld (but emoji domains are technically valid)
β
emmaly@xn--n28h.tld (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)