Skip to main content
Free developer tool

This libphonenumber parser shows what the library makes of any phone number, in plain words.

Type a number and pick the country it was dialled from. You get libphonenumber's own answers (possible or valid, the type of number, every format) with what each one means beside it, and the same parse in JavaScript, Python, Java and PHP. It runs libphonenumber-js 1.13.7 with the full metadata, in your browser.

Loading libphonenumber's numbering data...

A possible number has the right length, and a valid one also sits in a range the country hands out.

These eight numbers show where the two checks part ways. Every answer below came from the library when this page was built.

NumberisPossibleisValidgetType
+1 201 555 0123US example from the 555-01XX block set aside for fiction yes yesFIXED_LINE_OR_MOBILElandline or mobile
+1 211 555 0123211 is a service code, so no area code starts with it yes no none
+1 201 555 01234The US example with one digit too many noToo long for this country no none
+1 800 555 0199A toll-free 800 number yes yesTOLL_FREEtoll-free
+44 7400 123456libphonenumber's own UK mobile example yes yesMOBILEmobile
+44 7700 900123The UK range for mobiles in TV and film yes no none
+44 20 7946 0123The UK range for London numbers in TV and film yes yesFIXED_LINElandline
+61 491 570 156The Australian range for mobiles in TV and film yes yesMOBILEmobile

Each field the parser returns answers one narrow question.

The names are libphonenumber-js's. The Java original and its ports use the same ideas under longer names (isValidNumber, getNumberType).

phone.country
The two-letter country the number belongs to, or nothing when one calling code covers several and the digits do not say which.
phone.countryCallingCode
The digits after the + that pick the country: 1, 44, 91.
phone.nationalNumber
The number without its calling code and without the trunk 0 the country dials at home.
phone.isPossible()
The length fits some number in that country. Nothing more is checked.
phone.isValid()
The length and the leading digits fit a range the country hands out.
phone.getType()
Which kind of range the digits fall in: mobile, landline, toll-free and so on.
phone.getPossibleCountries()
Every country that shares the calling code and could own the number.
phone.ext
An extension typed after the number, such as ext. 204.

The same parse in four languages

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

const phone = parsePhoneNumberFromString("+1 201 555 0123", "US");
phone?.isValid();          // valid for the numbering plan
phone?.getType();          // MOBILE, FIXED_LINE, ...
phone?.format("E.164");    // what to store
libphonenumber in Python
# pip install phonenumbers
import phonenumbers
from phonenumbers import PhoneNumberFormat, number_type

p = phonenumbers.parse("+1 201 555 0123", "US")
phonenumbers.is_valid_number(p)
number_type(p)  # 1 = MOBILE, 0 = FIXED_LINE, ...
phonenumbers.format_number(p, PhoneNumberFormat.E164)
libphonenumber in Java
// com.googlecode.libphonenumber:libphonenumber
PhoneNumberUtil util = PhoneNumberUtil.getInstance();
Phonenumber.PhoneNumber p = util.parse("+1 201 555 0123", "US");
util.isValidNumber(p);
util.getNumberType(p);   // MOBILE, FIXED_LINE, ...
util.format(p, PhoneNumberUtil.PhoneNumberFormat.E164);
libphonenumber in PHP
// composer require giggsey/libphonenumber-for-php
use libphonenumber\PhoneNumberUtil;
use libphonenumber\PhoneNumberFormat;

$util = PhoneNumberUtil::getInstance();
$p = $util->parse('+1 201 555 0123', 'US');
$util->isValidNumber($p);
$util->getNumberType($p);
$util->format($p, PhoneNumberFormat::E164);

The smallest libphonenumber-js metadata gives no number type for most countries.

We ran every country's example mobile number, and two broken copies of each, through all three metadata sets of libphonenumber-js 1.13.7: 735 numbers from 245 countries.

min

84 KB, 20 KB gzipped

686 of 735 getType() answers differ from max, and 1 isValid() answer.

Fine for checking a number before you store it.

mobile

99 KB, 24 KB gzipped

Calls a London landline not valid and the US example MOBILE.

Only for forms that accept mobiles and nothing else.

max

158 KB, 40 KB gzipped

Every range and every type: the answers in the table above.

Use it whenever you call getType().

libphonenumber has a port for nearly every language, and they all share Google's metadata.

The answers come from the metadata, not the code, so two ports on the same metadata release agree. When they disagree, one of them is behind on updates.

LanguagePackageNotes
Javacom.googlecode.libphonenumber:libphonenumberThe original. Every other port follows its metadata.
JavaScriptlibphonenumber-jsA rewrite, much smaller than the original. This page runs it.
JavaScriptgoogle-libphonenumberThe original compiled to JavaScript. Bigger, same answers as Java.
PythonphonenumbersA full port, kept in step with each metadata release.
PHPgiggsey/libphonenumber-for-phpA full port, installed with Composer.
C#libphonenumber-csharpA full port for .NET, on NuGet.
Gogithub.com/nyaruka/phonenumbersA full port for Go.
RubyphonelibA Ruby gem built on the same metadata.
SwiftPhoneNumberKitAn iOS library built on the same metadata.

libphonenumber knows the numbering plan, but it cannot see the live line.

The library works from a file of ranges, so three questions are out of its reach. Each one has a free tool.

Is the number switched on today?

The library says a range exists, not that anyone has the number.

HLR lookup, free

Is a US number a mobile or a landline?

US and Canadian numbers come back FIXED_LINE_OR_MOBILE, and VoIP numbers look the same as the rest.

Line type lookup, free

Which network is it on now?

A number ported to a new carrier keeps its digits, so the range shows only the first owner.

Carrier lookup, free

These are the questions developers ask most about libphonenumber.

What is libphonenumber?

libphonenumber is Google's open-source library for parsing, formatting and validating phone numbers, the one Android uses. It knows every country's numbering plan: which lengths exist, which prefixes are handed out, and which are mobile, landline or toll-free. It has ports for JavaScript, Python, PHP, C#, Go, Ruby and Swift.

What is the difference between isPossibleNumber and isValidNumber?

isPossibleNumber checks only the length. isValidNumber also checks that the leading digits fall in a range the country hands out. +1 211 555 0123 is possible, because it has the right number of digits, but not valid, because no US area code starts with 211.

Why does libphonenumber return FIXED_LINE_OR_MOBILE for US numbers?

In the US and Canada, mobile and landline numbers come from the same ranges, so the numbering plan cannot tell them apart and libphonenumber returns FIXED_LINE_OR_MOBILE for almost every number. Only a lookup of the live line says whether it is a mobile, a landline or a VoIP number.

Does a valid number mean the phone is switched on?

No. Valid means the number sits in a range the country hands out, not that anyone has it. +1 201 555 0123 is valid in libphonenumber and belongs to no one, because the 555-0100 to 555-0199 block is kept for films and examples. An HLR lookup asks the mobile network whether the number is live today.

Which libphonenumber-js metadata should I use, min, mobile or max?

Use max if you call getType(). Across 735 test numbers from 245 countries, min gave a different getType() answer from max 686 times, mostly by giving none at all, and a different isValid() answer 1 time. The mobile set only knows mobile ranges, so it calls a London landline not valid. Measured with libphonenumber-js 1.13.7.

Why does libphonenumber reject the UK number 07700 900123?

07700 900000 to 900999 is the range Ofcom keeps for mobiles in TV and film, and libphonenumber leaves it out of the UK mobile ranges, so it comes back possible but not valid. Oddly, the matching London range, 020 7946 0000 to 0999, comes back as a valid landline.

Is the number I type sent anywhere?

No. The library runs in your browser, so the number never leaves this page. Only the live check, if you click it, sends the number to the HLR lookup.

One API call adds the live answers the library cannot give.

The 1Lookup phone API returns whether a number is valid, its real line type, its current carrier and whether it is reachable, in one request. Start with a 7-day free trial.

Get a free API key