Skip to content

isValidPhone

Validates whether a string is a well-formed E.164 international phone number. Requires a leading +, a non-zero country code, and 1–15 total digits. Common readability separators — spaces, hyphens, parentheses, and dots — are stripped before validation; any other character causes rejection.

import { isValidPhone } from "1o1-utils";
import { isValidPhone } from "1o1-utils/is-valid-phone";
function isValidPhone({ phone, country }: IsValidPhoneParams): boolean
NameTypeRequiredDescription
phoneunknownYesThe value to validate
countryCountryCodeNoISO 3166-1 alpha-2 country code. When set, enforces the dialing prefix and total digit length for that country. ~50 popular countries supported. Default: omitted

booleantrue if the value is a parseable E.164 phone number, false otherwise.

isValidPhone({ phone: "+5511999999999" }); // => true
isValidPhone({ phone: "+1 555 1234567" }); // => true
isValidPhone({ phone: "+44 (20) 7946-0958" }); // => true
isValidPhone({ phone: "+1.555.123.4567" }); // => true
isValidPhone({ phone: "11999999999" }); // => false (no country code)
isValidPhone({ phone: "+0123456789" }); // => false (country code starts with 0)
isValidPhone({ phone: "abc" }); // => false
isValidPhone({ phone: "" }); // => false
isValidPhone({ phone: null }); // => false
// Country-scoped validation
isValidPhone({ phone: "+5511999999999", country: "BR" }); // => true
isValidPhone({ phone: "+551133334444", country: "BR" }); // => true (BR landline)
isValidPhone({ phone: "+15551234567", country: "BR" }); // => false (US dial code)
isValidPhone({ phone: "+5511999", country: "BR" }); // => false (too short for BR)
isValidPhone({ phone: "+15551234567", country: "US" }); // => true

All ISO 3166-1 alpha-2 codes with an assigned ITU-T E.164 country code (~240 territories). Includes every UN member state plus dependent territories such as GG (Guernsey), IM (Isle of Man), JE (Jersey), BL (Saint Barthélemy), MF (Saint Martin), XK (Kosovo), BQ/CW/SX (former Netherlands Antilles), and minor Pacific islands (NU, TK, WF, etc.).

Passing a country outside this set returns false.

// Validate user input before sending
function notify(input: string) {
if (!isValidPhone({ phone: input })) {
throw new Error("Invalid phone");
}
return sms.send(input);
}
  • Non-string inputs (null, undefined, numbers, objects, arrays) return false.
  • Empty strings return false without invoking the regex.
  • Inputs longer than 32 characters are rejected immediately to avoid pathological regex work.
  • The leading + is mandatory — local-format numbers without a country code return false.
  • Country code cannot start with 0 (E.164 rule).
  • Total digit count must be 1–15 after separators are stripped; 16+ digits return false.
  • Allowed separators: space, hyphen, parentheses, dot. Any other character (/, _, letters, etc.) causes rejection.
  • Country validation checks the dialing prefix and total digit count only — it does not distinguish mobile vs fixed-line, nor verify area codes.
  • Countries that share a dialing prefix cannot be distinguished: passing country: "CA" accepts US numbers and vice-versa (NANP, +1); country: "RU" accepts numbers from any other +7 country (e.g. Kazakhstan).
  • Validation is structural — it does not check whether the country code, area code, or subscriber number actually exist. For carrier-grade validation, use a library backed by phone metadata (e.g. libphonenumber-js).

phone, validate phone, is phone, valid phone, phone number, e164, international phone

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 isValidPhone to validate a user-supplied phone number before submitting a form.