Is email¶
isEmail validates that a value is a general‑purpose email address.
It uses a permissive but reliable pattern suitable for everyday user input. The rule ensures the value resembles a conventional email address without enforcing strict RFC semantics. Any non‑string value or string that fails the pattern results in a single validation event. Otherwise, it produces no validation output.
Signature¶
Through the API:
.isEmail();
And internally:
export const isEmail: ValidationRule
(value: unknown, path: FieldPath) => Promise<ReadonlyArray<JaneEvent>>
Events¶
| Event code | Description |
|---|---|
type.not.valid |
Value is not a string. |
string.not.email |
String does not match the general pattern. |
Design rationale¶
- Provides a permissive, user‑friendly email validator appropriate for common forms and input fields.
- Rejects non‑string values early with a structural‑type diagnostic.
- Uses a simple, well‑established pattern:
/^[^\s@]+@[^\s@]+\.[^\s@]+$/. - Avoids strict RFC enforcement — contributors should use isEmailStrict when needed.
- Emits exactly one event per failure for clarity and composability.
- Pure, total, async‑compatible, and returns a readonly array of
JaneEventobjects. - Preserves the provided path and supports pipeline‑level
userMessageoverrides.
Invoke¶
isEmail runs only when explicitly included in a boundary or pipeline. It does not run automatically.
The rule activates when:
- The value is any JavaScript value.
- If the value is not a string, emits
type.not.valid. - If the string does not match
/^[^\s@]+@[^\s@]+\.[^\s@]+$/, emitsstring.not.email. - Otherwise, returns an empty result set.
Examples¶
Valid — general‑purpose email addresses¶
await isEmail("user@example.com", "$");
// → []
await isEmail("john.doe+tag@domain.co", "$");
// → []
Invalid — non‑string values¶
await isEmail(123, "$");
// → [
// JaneEvent{
// kind: "error",
// code: "type.not.valid",
// path: "$",
// ...
// }
// ]
Invalid — incorrect format¶
await isEmail("user@", "$");
// → [
// JaneEvent{
// kind: "error",
// code: "string.not.email",
// path: "$",
// ...
// }
// ]
await isEmail("user@domain", "$"); // missing TLD
// → [
// JaneEvent{
// kind: "error",
// code: "string.not.email",
// path: "$",
// ...
// }
// ]