Blog
libphonenumber: what Google's library knows, what it skips and where it goes stale
A practical guide to libphonenumber and its JavaScript port: the metadata inside, possible versus valid, number types, parsing rules, blind spots and data lag.
Updated 2026-11-24
libphonenumber is Google's library for handling international phone numbers, and the metadata inside it is the reference most other tools copy from. It knows each country's calling code, number lengths, patterns for each line type and formatting rules. It does not know what happened to a number after its range was assigned, which is why it can say a number is well formed and cannot say anyone answers it. This guide covers what is in the data, how the JavaScript port behaves, and where it can mislead you.
What libphonenumber is
Google's libphonenumber is written in Java and C++, and the libphonenumber-js README mentions an official, autogenerated JavaScript port. A metadata file of country rules drives all of it. Because the data is open, many projects reuse it, including libphonenumber-js, a rewrite in JavaScript and TypeScript by a different author.
| Google's libphonenumber | libphonenumber-js | |
|---|---|---|
| Language | Java and C++, plus a generated JavaScript port | JavaScript and TypeScript |
| Size, according to its README | About 550 kB in the compiled JavaScript bundle | About 145 kB with the full metadata, 80 kB with the min metadata |
| Searches text for numbers | Not in the JavaScript port | Yes, findPhoneNumbersInText |
| Geocoding of numbers to a city | Yes, as separate data | No |
| Carrier prefix data | Yes, as separate data | No |
| Special cases (emergency numbers, short codes) | Handled | Skipped on purpose |
The sizes and the list of differences come from the libphonenumber-js README for version 1.13.17. Check the current README before you rely on a figure.
What is in the metadata
For each country or region, the data holds:
- The country calling code, one to three digits, from ITU-T Recommendation E.164, and the international and national prefixes.
- The national number rules: the lengths that are possible, and a pattern that says which digits are valid.
- Patterns per number type: fixed line, mobile, toll free, premium rate, shared cost, VoIP, personal number, pager, UAN and voicemail.
- Formats: how to group the digits for national and international display.
- Example numbers, used to show a sample in a form.
The library also knows non-geographic plans, such as satellite services, where a number has no country. In libphonenumber-js, .country is undefined for those, and isNonGeographic() tells you.
Google's project ships three more kinds of data as separate files: a carrier mapper (prefix to the operator that first received it), a geocoder (prefix to a place) and time zones. The Qelka phone API reads the plan data, plus the carrier, time zone and example files, which is why a basic result carries a region, time zones and an original range holder.
Possible versus valid
These two words carry most of the confusion. libphonenumber-js defines them in its README:
isPossible()checks only the length. It does not look at the digits.isValid()checks the length, then checks the digits against the patterns of the country.
| Number | Possible | Valid | Why |
|---|---|---|---|
+44 7400 12345 |
Yes | No | Nine digits is a legal UK length, but UK mobile numbers beginning with 7 have ten |
+1 123 456 7890 |
Yes | No | Ten digits is the right length, but a North American area code never begins with 1 |
+44 7400 123456 |
Yes | Yes | A UK mobile number |
415 with country US |
No | No | Too short for any US number |
These results come from running the library, with the max metadata, on the numbers shown.
There is a catch with the default build. The README says that the default min metadata leaves out the precise patterns, so there isValid() behaves as if it were isPossible(). To get the real digit check, import from libphonenumber-js/max, or libphonenumber-js/mobile if you only accept mobile numbers.
Number types
getType() returns the type of the range a number falls in. The values are MOBILE, FIXED_LINE, FIXED_LINE_OR_MOBILE, PREMIUM_RATE, TOLL_FREE, SHARED_COST, VOIP, PERSONAL_NUMBER, PAGER, UAN and VOICEMAIL, or undefined when the metadata has no pattern for the country or the number is invalid.
Three limits are worth knowing:
- North America does not split mobile and landline. Numbers there come back
FIXED_LINE_OR_MOBILE, as the plan itself does not distinguish them. VOIPappears only where a country reserved ranges for it. Internet phone services that hand out ordinary mobile or geographic numbers look like any other number.- The type describes the range, not the phone. A number ported between a landline and a mobile operator keeps the type of its original range.
The Qelka API reports the same values in lower case with underscores: mobile, landline, fixed_line_or_mobile, voip, toll_free, premium_rate and the rest. See mobile, landline or VoIP for what to do with each.
Parsing rules worth knowing
import parsePhoneNumber, { getCountries, getCountryCallingCode, isSupportedCountry } from 'libphonenumber-js/max'
console.log(getCountries().length, getCountryCallingCode('GB'), isSupportedCountry('XX'))
const withExtension = parsePhoneNumber('+1 (415) 555-0123 x 12')
console.log(withExtension.number, withExtension.ext, withExtension.getURI())
const national = parsePhoneNumber('07400 123456', 'GB')
console.log(national.number, national.formatInternational())
In the version we ran, getCountries() returned 245 entries, the calling code for GB is 44, XX is not a supported country and the extension is kept apart: +14155550123, extension 12, URI tel:+14155550123;ext=12.
Rules that surprise people:
- A number without a
+needs a country. Without it, parsing fails withINVALID_COUNTRY. The library does not guess. - The trunk prefix is dropped. The leading
0in07400 123456is a national dialing prefix and is not part of the E.164 number. It also drops a stray(0)after the country code:+44 (0) 7400 123456becomes+447400123456. - The international prefix depends on the country you passed.
00 44 7400 123456parsed with a US default country does not read as+44, because the US prefix is011. Send the+form when you can. - Extension markers vary.
ext.andxare recognised, and the extension is kept out ofnumber. - Parsing extracts by default. Without
extract: false,Call (415) 555-0123yields a number. Turn it off when the whole input must be a number. - Some local forms are rejected. The README says
libphonenumber-jsskips emergency numbers, short codes, numbers starting with*, alphabetic numbers like1-800-GOT-MILKand local numbers without an area code.
Where it goes stale
Numbering plans change. Regulators open ranges, retire old ones and add overlay area codes when a region runs short. The library knows what its data knew at release time, so there are two failure modes:
- Too strict. A newly opened range fails
isValid()until the package updates. Thelibphonenumber-jsREADME says as much: it warns thatisValid()can reject freshly allocated ranges on a site that nobody keeps up to date, and its author would personally preferisPossible()for that reason. - Too loose. A number in a retired or never-assigned block still passes, since the plan lists what can exist, not what is assigned.
The same property that makes a plan check instant makes it blind. It cannot see a disconnected number, a ported number or a recycled one. For those you need a network view: a live lookup for the current carrier and porting, and a one-time code for possession. See mobile number portability.
Keep the package current. Update it with the rest of your dependencies, take every release on a server you operate, and remember that a bundle shipped to browsers keeps the data it had on the day it was built.
Choosing where it runs
| Where | Fit | Limits |
|---|---|---|
| In the browser | Instant feedback, formatting as the user types, a country picker | Bundle size, old data in cached bundles, bypassable |
| On your server | The decision that counts; no size pressure | You update the package; no network view |
| In an API such as Qelka's | Current data without redeploys; line type, carrier and porting at the live level | A network call, and credits |
Most teams use two of the three: a light parse in the browser and the real check on the server. Validate phone numbers in JavaScript shows the code.
What the Qelka API adds
A library gives you the plan. The API starts from the same plan data and adds what a static package cannot hold.
| Question | libphonenumber alone | Qelka phone API |
|---|---|---|
| Is the number valid? | Yes | Yes, status and valid |
| Which E.164 form? | Yes | e164, and national |
| Region and time zones? | Time zones as separate data | region, timezones |
| Original range holder? | Carrier mapper, separate data | carrier.name with carrier.source: "numbering_plan" |
Current carrier and ported? |
No | Live level: carrier.name, carrier.mcc, carrier.mnc and ported |
| Result for a bad input | An exception or undefined |
status: "unknown" when no country was given, invalid otherwise |
At the basic level the API costs 1 credit and sends the number nowhere. The live level costs 3 credits and sends it to the lookup provider. See the phone API reference, and for the free version of the plan check, the phone validator.
A short checklist
- Use the
maxbuild when you wantisValid()andgetType()to mean what they say. - Pass a country for every number typed without a
+. - Pass
extract: falsewhen parsing form input. - Store
numberin E.164 and the extension in its own column. - Decide on possible versus valid on purpose, knowing the staleness trade.
- Update the package on a schedule.
- Add a network lookup and a one-time code for the layers a library cannot see.
Where to go next
- Phone number validation for the layers in order.
- Phone number formats by country for how plans differ.
- E.164 explained for the storage format.
- Phone validation API for pricing and volumes.
Frequently asked questions
What is libphonenumber?
libphonenumber-js, a smaller rewrite for JavaScript and TypeScript.What is the difference between libphonenumber and libphonenumber-js?
libphonenumber-js is a rewrite in JavaScript and TypeScript that starts from Google's metadata but changes the code and lets you choose how much metadata to ship. Its README lists the differences: it is smaller, searches text for numbers, and skips special cases such as emergency numbers and short codes. It does not provide the geolocation feature of the original.Does libphonenumber check whether a number is in service?
Why does libphonenumber reject a number that works?
libphonenumber-js README warns that isValid() can reject freshly assigned ranges in a site that is not kept up to date. Update the package, or fall back to a length check when you must not turn anyone away.Can libphonenumber tell me the carrier of a number?
libphonenumber-js does not include it. For the operator serving the number today, you need a live lookup that returns the current carrier and a porting flag.How often should I update libphonenumber?
Put this check in your product
Get an API key in under a minute. 100 free credits every month, no card required.
- 100 free credits a month
- No card
- Test keys spend nothing
- Cancel any time