Tutorial · JavaScript

Validate phone numbers in JavaScript

From a quick regex to full numbering-plan validation with carrier and line type: three ways to validate phone numbers in the browser and in Node.js.

Updated October 1, 2026 · 2 min read

1. Regex: shape only

A regex is fine as a first filter, for example to reject letters in an input field:

const E164 = /^\+[1-9]\d{1,14}$/;
E164.test("+442079460958"); // true
E164.test("+15555555555");  // true, but not a real number

It cannot know that UK mobile numbers start with 7, that German numbers have 6 to 13 digits, or that 555 numbers are fictional.

2. libphonenumber-js: numbering-plan validation

libphonenumber-js is a JavaScript port of Google’s libphonenumber with the official metadata for every country.

npm install libphonenumber-js
import { parsePhoneNumberFromString } from "libphonenumber-js/max";

const phone = parsePhoneNumberFromString("07400 123456", "GB");
if (phone && phone.isValid()) {
  console.log(phone.number);               // "+447400123456"  (E.164, store this)
  console.log(phone.formatInternational()); // "+44 7400 123456"
  console.log(phone.getType());             // "MOBILE"
  console.log(phone.country);               // "GB"
}

This is exactly what the free phone number validator on this site runs.

3. A phone validation API: carrier, line type, trusted result

Client-side checks are easy to bypass and cannot tell you the carrier. For sign-ups, SMS sending and fraud checks, validate on the server with the numlookupapi API:

// Node.js 18+ (built-in fetch)
async function validatePhone(number) {
  const url = `https://api.numlookupapi.com/v1/validate/${encodeURIComponent(number)}`;
  const res = await fetch(url, { headers: { apikey: process.env.NUMLOOKUP_API_KEY } });
  if (!res.ok) throw new Error(`numlookupapi ${res.status}`);
  return res.json();
}

const result = await validatePhone("+14158586273");
// { valid: true, line_type: "mobile", carrier: "AT&T Mobility LLC",
//   country_code: "US", location: "Novato", e164_format: "+14158586273", ... }

Numbers without a country code can be validated with ?country_code=GB. To check up to 100 numbers per request, POST /v1/validate with {"numbers": [...]}.

Putting it together in a form

  1. Validate with libphonenumber-js while the user types and show a hint.
  2. On submit, call your backend, which calls the API and stores e164_format.
  3. Reject valid: false, and decide what to do with line_type: "voip" if you need real mobile numbers (e.g. for two-factor authentication).

Get a free API key with 100 requests per month on the pricing page.

Frequently asked questions

What is the best way to validate phone numbers in JavaScript?

Use libphonenumber-js for format and numbering-plan checks in the browser, and a phone validation API on the server when you also need the carrier, line type or a check you can trust (client-side checks can be bypassed).

Is there a regex that validates all phone numbers?

No. A regex can check the E.164 shape (^\+[1-9]\d{1,14}$), but number lengths and valid prefixes differ by country, so only numbering-plan data can tell whether a number really exists.

How big is libphonenumber-js?

The default 'min' metadata is about 80 kB minified; the 'max' build, needed for exact number types such as mobile vs landline, is roughly 145 kB. Load it only on pages that need it.

Phone number API

Validate numbers like this in your app

numlookupapi checks any phone number worldwide in one request and returns validity, line type, carrier, location and every standard format as JSON.

Read the documentation

100 free requests every month. No credit card required.

GET https://api.numlookupapi.com/v1/validate/+12069220880

{
  "valid": true,
  "number": "12069220880",
  "local_format": "2069220880",
  "international_format": "+12069220880",
  "country_prefix": "+1",
  "country_code": "US",
  "country_name": "United States of America",
  "location": "Seattle",
  "line_type": "landline",
  "e164_format": "+12069220880",
  "national_format": "(206) 922-0880"
}

Keep reading

Start using our Phone number API for free today!

Get 100 requests / month for free