Input rules
What normalize and extract accept, and what they reject on purpose.
Supported numbers
| Type | Numbers | Notation | International |
|---|---|---|---|
fixed_line | Area code + local exchange, 10 digits | From the MIC tables, such as 03-5253-8111 or 04998-2-3111 | Yes |
mobile | 060, 070, 080, 090, 11 digits | 090-1234-5678 | Yes |
ip_phone | 050, 11 digits | 050-1234-5678 | Yes |
toll_free | 0120 (10 digits), 0800 (11 digits) | 0120-123-456, 0800-123-4567 | No |
unified_number | 0570, 10 digits | 0570-123-456 | No |
Fixed-line hyphens come from the MIC tables, not from the brackets in the input, so 0922(12)1234 becomes 092-212-1234. Blocks marked unused in the tables are accepted.
Not supported: 020 (data transmission mobile), 0990, short codes such as 110, and numbers from other countries.
normalize
normalize takes one value. It accepts:
- half-width and full-width digits, and the single-digit kanji
〇一二三四五六七八九; - half-width and full-width spaces, hyphens (
-,-,‐,‑,−), and brackets around the local exchange or the whole number; +81, including the bracketed domestic0in+81-(0)50-3818-1250, for fixed-line, mobile, and 050;- a leading
TEL:,FAX:,電話:, or電話番号:, and a trailing(代表),(代),(直通), or extension written with内線.
It rejects, on purpose:
- broken separators such as
090--1234-5678or an unclosed bracket; - letters mixed into digits, such as
090-ABCD-5678; - line breaks or tabs, more than one number, or other words around the number;
- values longer than 128 characters;
+810…without brackets, and kanji with place values such as十or零;- numbers without an area code. japan-phone never guesses one.
extract
extract takes text of any length and returns the numbers it finds, in order.
- Any text may surround a number, including line breaks.
- It joins digit groups separated by up to three half-width or full-width spaces, hyphens (including
ーand dashes), brackets, or periods. - Each candidate is validated as strictly as by
normalize. Digit strings that do not fit the numbering plan or the MIC tables are skipped. - It never cuts a number out of a longer run of digits. Digits of other scripts, such as Arabic-Indic, count as part of the run (for example, nothing is found in
١09012345678). The digits are fixed to the decimal digits of Unicode 18.0, so they do not change with the Unicode version of the runtime. - It ignores where the separators fall. Misgrouped numbers such as
0120-12-3456or0922-12-1234are returned with the correct grouping. As a result, other digit strings of the same length, such as part numbers, are picked up when they happen to fall in a valid block (for example,0352-538-111becomes03-5253-8111). +81is read for fixed-line, mobile, and 050 numbers, including+81-0-90-1234-5678with the domestic0written as its own group.- Digits after a
+other than+81, such as+1or+999, are treated as a foreign number and skipped with the digits joined to them, also with up to three separators between the+and the digits (+ 1,+(1)).+1 090-1234-5678never yields a Japanese number. As a result, a number after a decorative or arithmetic+, as in1+1 090-1234-5678or基本料金 + 090-1234-5678, is not found either. When four or more characters, or a character that is not a separator, come between the+and the digits (as in+ (要予約) 090-1234-5678), the+does not count and the number is found. - The same number written twice is returned twice.