Getting started
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
pip install japan-phone
<dependency>
<groupId>jp.kurashina</groupId>
<artifactId>japan-phone</artifactId>
<version>0.9.0</version>
</dependency>
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
| Function | Use it for | Not a phone number |
|---|---|---|
normalize | One value, such as a form field | null · None · Optional.empty() |
isValid (is_valid) | A yes-or-no check | false |
extract | Free text with any number of phone numbers | An 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
from japan_phone import extract, is_valid, normalize
normalize("〇九〇-一二三四-五六七八").national # "090-1234-5678"
is_valid("03-1234-5678") # False
len(extract("日中は090-1234-5678、夜は092-513-5612まで")) # 2
import jp.kurashina.japanphone.JapanPhone;
JapanPhone.normalize("〇九〇-一二三四-五六七八").get().getNational(); // "090-1234-5678"
JapanPhone.isValid("03-1234-5678"); // false
JapanPhone.extract("日中は090-1234-5678、夜は092-513-5612まで").size(); // 2
The result
| Field | Example | Meaning |
|---|---|---|
national | 03-5253-8111 | The domestic notation with hyphens |
digits | 0352538111 | Digits only, with the leading 0 |
international | +81352538111 | E.164. Empty for 0120, 0800, and 0570 |
type | fixed_line | fixed_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.