Email address validation.
Validate
- JavaScript library
- Python library13 cases fail
- Go library13 cases fail
- Ruby library7 cases fail
- Rust library11 cases fail
- .NET library7 cases fail
- Erlang library
Validates an email address: a practical subset of the WHATWG HTML "valid e-mail address".
- Local part: letters, digits and
_'+-., with no leading or trailing dot, no trailing apostrophe and no two dots in a row, at most 64 characters. The whole address is capped at 254 characters (RFC 5321, section 4.5.3.1). Until 2.4.0 there was no cap on either. - Domain: at least one dot, labels of up to 63 characters that neither start nor end with a hyphen, the final label 2 to 63 letters or a punycode label (
xn--, up to 63 characters, souser@example.xn--p1aiis valid). A punycode label with nothing afterxn--, ending in a hyphen or over 63 characters is rejected. Until 2.4.0 a punycode final label was rejected. - Quoted local parts, address literals, single-label domains such as
user@localhostand the local part characters! # $ % & * = ? ^ { | } ~, the slash and the backtick are rejected, although WHATWG allows some of them. - The check ignores case. A value that is not a string is invalid.
- A Pix email key does not use this function.
pixKey.isValidfollows the pattern of the DICT API, which is wider in some places: it acceptsfulano@example,a@localhostanda{b}@example.com, which this function rejects.
| Parameter | Type | Required |
|---|---|---|
value | string | yes |
| returns | boolean |
Check if an email address is valid. A practical subset of the WHATWG HTML definition.
- Local part: letters, digits and
_'+-., with no leading or trailing dot, no trailing apostrophe and no two dots in a row, and at most 64 characters. The whole address is capped at 254 characters (RFC 5321, section 4.5.3.1); up to 2.4.0 there was no cap on either. - Domain: at least one dot, labels of up to 63 characters, final label 2 to 63 letters or a punycode label (
xn--, up to 63 characters, souser@example.xn--p1aiis valid). - Rejected, although WHATWG allows some of them: quoted local parts, address literals, single label domains such as
user@localhost, and the local part characters! # $ % & * = ? ^ { | } ~, the slash and the backtick.
import { isValidEmail } from '@brazilian-utils/brazilian-utils';
isValidEmail('john.doe@hotmail.com'); // true
isValidEmail('invalid.email'); // false
isValidEmail('user@example.xn--p1ai'); // true (punycode top-level domain)
isValidEmail('a%b@example.com'); // false (% is outside the accepted local part set)Source: WHATWG HTML, valid e-mail address and RFC 5322.
Code: brazilian-utils/javascriptTry it with JavaScript isValidEmail
Shared test cases (51) and the result in each library email.isValid
Official sources
See also Pix key
Last updated on
