Examples

The same task in Node.js, Python, and Java, with its output. Each example also has a demo you can try in your browser, running on the table bundled with the library.

Forms

Input fields: validate, accept pasted text, check the type, link.

Validate a phone number field
Accept full-width input, reject numbers that do not exist, and save one notation.
normalize
Accept pasted labels and notes
Take the main number from lines like
normalize
Accept mobile numbers only
Use the type to decide whether a number can receive SMS.
normalizetype
Make tel: links
Link numbers in their international form, and keep domestic-only numbers dialable.
normalizeinternational

Finding numbers in text

Pick phone numbers out of messages, pages, and business cards.

Find numbers in a message
Pick every phone number out of a message, in the order it appears.
extract
Read a business card in kanji digits
Find numbers written with 〇一二三, as on vertical business cards.
extract
List the numbers on a company page
Find TEL and FAX numbers and drop duplicates written in other notations.
extractdigits

Data and storage

Clean, deduplicate, count, and convert stored numbers.

Store digits, show hyphens
Format stored digits with the groups from the numbering table.
normalizenational
Find duplicates written differently
Group entries that are the same number in different notations.
normalize
Clean a CSV column
Rewrite a phone column in one notation and flag rows that need a person.
normalize
Count numbers by type
See how many entries are mobile, fixed-line, toll-free, or invalid.
normalizetype
Convert to E.164
Pass numbers to SMS gateways, CRMs, and libphonenumber in international form.
normalizeinternational

Validity rules

Which numbers japan-phone rejects, and why.

Reject numbers that cannot exist
Numbers missing from the numbering plan or the MIC tables are invalid.
isValid
Read numbers written for abroad
Accept +81 notation, including the bracketed (0), for the types that can be dialed from abroad.
normalize