Getting started

Install japan-phone for Node.js, Python, or Java and learn its three functions.

japan-phone validates and formats Japanese phone numbers using only the numbering plan and the fixed-line tables published by the Ministry of Internal Affairs and Communications (MIC). The Node.js, Python, and Java libraries bundle the same table, pass the same tests, and return the same results. They need no network access and have no runtime dependencies.

Install

npm install @kurashina-design/japan-phone

Node.js 22 or later, Python 3.11 or later, and Java 8 or later are supported. Each is the oldest release line that still receives security updates. The npm package also runs in browsers (In the browser and with frameworks).

Three functions

FunctionUse it forNot a phone number
normalizeOne value, such as a form fieldnull · None · Optional.empty()
isValid (is_valid)A yes-or-no checkfalse
extractFree text with any number of phone numbersAn empty list
import { normalize, isValid, extract } from "@kurashina-design/japan-phone";

normalize("〇九〇-一二三四-五六七八");
// { national: "090-1234-5678", digits: "09012345678",
//   international: "+819012345678", type: "mobile" }
isValid("03-1234-5678"); // false
extract("日中は090-1234-5678、夜は092-513-5612まで"); // two results

The result

FieldExampleMeaning
national03-5253-8111The domestic notation with hyphens
digits0352538111Digits only, with the leading 0
international+81352538111E.164. Empty for 0120, 0800, and 0570
typefixed_linefixed_line, mobile, ip_phone, toll_free, or unified_number

In Java, read the fields with getters. getInternational() returns Optional<String>. getType() returns the JapanPhoneType enum (FIXED_LINE and so on); its getValue() and toString() return the same string as the other languages, such as fixed_line. Two results are equals when all their fields are equal.

What "valid" means

A valid number has the structure of a supported type and belongs to a block in the numbering plan or the MIC tables. It does not mean that the number is subscribed, reachable, or able to receive SMS. Check that with your telephony or SMS provider.