Online Playground
Browse tools

libphonenumber-js Playground

Try libphonenumber-js online. Type a number and see the exact object it returns, with the code that produces it.

libphonenumber-js playground

Try
Result the object the library returns
Code paste it into your project

Runs libphonenumber-js 1.13.15 with the max metadata build, in your browser.

Processed locally with libphonenumber-js. Nothing you enter is sent to a server.

How it works

Three steps, all in your browser

  1. 1

    Type a number

    With a + prefix, or choose a default country for a local number.

  2. 2

    Read the output

    See the parsed object as JSON, exactly as libphonenumber-js returns it.

  3. 3

    Copy the code

    The snippet changes with your input, so you can paste it into your project.

In depth

The object this page shows you

These values are the result of parsing +44 20 7946 0958 with the max data set. They are the fields your own code can read from the parsed number.

Field or methodResult
number+442079460958
countryGB
countryCallingCode44
nationalNumber2079460958
isValid()true
isPossible()true
getType()FIXED_LINE
formatInternational()+44 20 7946 0958
formatNational()020 7946 0958
getURI()tel:+442079460958

isPossible() and isValid() are different checks

isPossible() checks only that the length fits the country. isValid() also checks the digits against the ranges assigned in that country. The library's author prefers isPossible() for forms, because numbering plans change and an out-of-date copy of the library could reject a newly assigned range. Here is how they differ on real input.

InputDefault countryisPossible()isValid()
0000000000UStruefalse
12345USfalsefalse (TOO_SHORT)
+91 1000000000truefalse

Strict parsing with extract: false

By default the parser extracts a number from surrounding text, which mimics Google's library. The input "Call: (213) 373-4253" parses to +12133734253. With extract: false it returns undefined, so text around the number makes it fail. Tick "Strict parsing" above to see both, together with the code to copy.

min, max and mobile builds

This playground runs the max data set so every field is filled in. If your project uses the default min build, getType() returns nothing for many countries, and isValid() is more lenient because it does not check digits against exact ranges for most countries. Choose the build in the import path: libphonenumber-js, libphonenumber-js/max or libphonenumber-js/mobile. The install guide has measured sizes for each.

FAQ

Questions people ask

What is libphonenumber-js?

It is a JavaScript library that parses, formats and validates phone numbers for every country. It is a smaller rewrite of Google's libphonenumber that runs in browsers and Node.js.

Is this the official libphonenumber-js demo?

No. This is an independent playground that runs the real library in your browser. It is not affiliated with Google or with the library's author.

Which version and build does the playground run?

It runs version 1.13.15 with the max metadata build, so number types are available. Your own project may use the smaller min build, which has type data for only some countries and validates digits more loosely.

Is the number I type sent anywhere?

No. The library runs in your browser and nothing is sent to a server.