API reference › @evolu/common › Type › PhoneNumberE164
const PhoneNumberE164: brand(
"PhoneNumberE164",
String,
(value: string) =>
/^\+[1-9]\d{6,14}$/u.test(value)
? ok()
: err<PhoneNumberE164Error>({ type: "PhoneNumberE164", value }),
formatPhoneNumberE164Error,
);
Defined in: packages/common/src/Type.ts:9683
International phone number in ITU-T E.164 format.
PhoneNumberE164 accepts a + followed by 7 to 15 ASCII digits, the first of
which is not zero, such as +14155552671. E.164 limits numbers to 15 digits,
and no country code starts with zero. The 7-digit minimum admits the shortest
numbering plans.
The check is structural only. PhoneNumberE164 does not check country codes or
national numbering plans, which are large and changing metadata, so a valid
value is not necessarily an assigned number. It does not normalize either:
spaces, hyphens, parentheses, a 00 international prefix, and extensions are
rejected. Format user input to E.164 with a library such as libphonenumber
before validating it.
Example
import {
assertEqual,
assertErr,
assertOk,
PhoneNumberE164,
} from "@evolu/common";
assertOk(PhoneNumberE164.fromUnknown("+14155552671"), "+14155552671");
const invalid = PhoneNumberE164.fromUnknown("+1 415 555 2671");
assertErr(invalid);
assertEqual(invalid.error, {
type: "PhoneNumberE164",
value: "+1 415 555 2671",
});