Skip to content

Is phone strict

isPhoneStrict validates that a value is a strict E.164 international phone number.

It enforces canonical E.164 formatting: the value must be a string beginning with a plus sign followed by 8–15 digits. Any non‑string value or string that fails the strict pattern results in a single validation event. Otherwise, it produces no validation output.

Signature

Through the API:

.isPhoneStrict();

And internally:

export const isPhoneStrict: ValidationRule
(value: unknown, path: FieldPath) => Promise<ReadonlyArray<JaneEvent>>

Events

Event code Description
type.not.valid Value is not a string.
string.not.strict-phone String does not match the strict E.164 pattern.

Design rationale

  • Enforces strict E.164 formatting: + followed by 8–15 digits.
  • Rejects non‑string values early with a structural‑type diagnostic.
  • Avoids normalization — contributors must provide canonical international numbers.
  • Ensures globally portable, unambiguous phone identifiers.
  • Emits exactly one event per failure for clarity and composability.
  • Pure, total, async‑compatible, and returns a readonly array of JaneEvent objects.
  • Preserves the provided path and supports pipeline‑level userMessage overrides.

Invoke

isPhoneStrict 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 /^\+[1-9]\d{7,14}$/, emits string.not.strict-phone.
  • Otherwise, returns an empty result set.

Examples

Valid — strict E.164 numbers

await isPhoneStrict("+15551234567", "$");
// → []

await isPhoneStrict("+447911123456", "$");
// → []

Invalid — non‑string values

await isPhoneStrict(12345, "$");
// → [
//     JaneEvent{
//       kind: "error",
//       code: "type.not.valid",
//       path: "$",
//       ...
//     }
//   ]

Invalid — incorrect format

await isPhoneStrict("555-123-4567", "$");
// → [
//     JaneEvent{
//       kind: "error",
//       code: "string.not.strict-phone",
//       path: "$",
//       ...
//     }
//   ]

await isPhoneStrict("+1-555-123-4567", "$"); // contains hyphens
// → [
//     JaneEvent{
//       kind: "error",
//       code: "string.not.strict-phone",
//       path: "$",
//       ...
//     }
//   ]