/** RFC 5321 max mailbox length (no angle brackets). */ export const EMAIL_MAX_LEN = 254; /** * Fallback when `HTMLInputElement.checkValidity()` is unavailable (SSR). * Matches the HTML living standard’s type=email pattern closely enough * for the save-progress field; the live input is the source of truth in * the browser. */ const EMAIL_FALLBACK_PATTERN = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/; /** * Whether a create-flow save-progress email would pass a required * `type="email"` input’s `checkValidity()`. Does not trim: native * validity rejects leading or trailing spaces. */ export function isValidCreateFlowSaveEmail(value: unknown): boolean { if (typeof value !== "string") return false; if (value.length === 0 || value.length > EMAIL_MAX_LEN) return false; // Native type=email rejects whitespace; jsdom’s checkValidity does not. if (/\s/.test(value)) return false; if (typeof document === "undefined") { return EMAIL_FALLBACK_PATTERN.test(value); } const input = document.createElement("input"); input.type = "email"; input.required = true; input.value = value; return input.checkValidity(); }