isValidEmail
Validates whether a string is a well-formed email address. Uses the HTML5 living-standard email pattern (the same one browsers use for <input type="email">) plus RFC 5321 length limits (local part ≤64, total ≤254). Pragmatic over RFC 5322 strict — accepts the addresses people actually use.
Try it
Section titled “Try it”Import
Section titled “Import”import { isValidEmail } from "1o1-utils";import { isValidEmail } from "1o1-utils/is-valid-email";Signature
Section titled “Signature”function isValidEmail({ email, allowDisplayName }: IsValidEmailParams): booleanParameters
Section titled “Parameters”| Name | Type | Required | Description |
|---|---|---|---|
email | unknown | Yes | The value to validate |
allowDisplayName | boolean | No | When true, also accepts display-name form like "Jane Doe <jane@example.com>" or '"Doe, Jane" <jane@example.com>'. Default false |
Returns
Section titled “Returns”boolean — true if the value is a parseable email, false otherwise.
Examples
Section titled “Examples”isValidEmail({ email: "user@example.com" }); // => trueisValidEmail({ email: "user+tag@gmail.com" }); // => trueisValidEmail({ email: "first.last@sub.example.io" }); // => true
isValidEmail({ email: "invalid@" }); // => falseisValidEmail({ email: "no-at-sign.com" }); // => falseisValidEmail({ email: "" }); // => falseisValidEmail({ email: null }); // => false// Display-name form (opt-in)isValidEmail({ email: "Jane Doe <jane@example.com>", allowDisplayName: true,}); // => true
isValidEmail({ email: '"Doe, Jane" <jane@example.com>', allowDisplayName: true,}); // => true
isValidEmail({ email: "Jane Doe <jane@example.com>",}); // => false (not allowed by default)// Validate user input before sendingfunction subscribe(input: string) { if (!isValidEmail({ email: input })) { throw new Error("Invalid email"); } return api.subscribe(input);}Edge Cases
Section titled “Edge Cases”- Non-string inputs (
null,undefined, numbers, objects, arrays) returnfalse. - Empty strings return
falsewithout invoking the regex. - Length-bounded: local part > 64 chars, total > 254 chars, or raw input > 320 chars returns
false(the 320-char input cap blocks pathological payloads before any regex work). - Hostname labels cannot start or end with a hyphen, and empty labels (
example..com) are rejected. - Whitespace and control characters anywhere in the address return
falseunlessallowDisplayNameis set and the wrapper itself contains whitespace. - ASCII-only host part — internationalized domain names (IDN) such as
user@münchen.dereturnfalse. Convert IDN hosts to Punycode (e.g.,user@xn--mnchen-3ya.de) before validating. - Consecutive, leading, or trailing dots in the local part (e.g.,
a..b@example.com,.user@example.com) are accepted — matches the HTML5 living standard. RFC 5322 strict disallows them; this validator favors HTML5 compatibility. - The validator is structural — it does not perform DNS, MX, or SMTP checks.
Also known as
Section titled “Also known as”email, validate email, is email, valid email, email check, email validator
Prompt suggestion
Section titled “Prompt suggestion”I'm using 1o1-utils (npm: https://www.npmjs.com/package/1o1-utils, GitHub: https://github.com/pedrotroccoli/1o1-utils, LLM context: https://pedrotroccoli.github.io/1o1-utils/llms.txt). Show me how to use isValidEmail to validate a user-supplied email before submitting a form.