Validity rules
Read numbers written for abroad
normalize
Accept +81 notation, including the bracketed (0), for the types that can be dialed from abroad.
Try it
050-3818-1250090-1234-567803-5253-8111- rejected
- rejected
How it works
Numbers on English pages are often written as +81-(0)50-3818-1250 or +81 90-1234-5678. normalize accepts +81 for fixed-line, mobile, and 050 numbers, and drops the bracketed domestic 0.
- Toll-free and 0570 numbers cannot be dialed from abroad, so
+81 120 123 456is rejected. +810352538111, with the0kept but not in brackets, is rejected as a broken notation.
In each language
import { normalize } from "@kurashina-design/japan-phone";
// Numbers written for callers abroad.
const inputs = ["+81-(0)50-3818-1250", "+81 90-1234-5678", "+81-3-5253-8111", "+81 120 123 456", "+810352538111"];
for (const input of inputs) console.log(input, "->", normalize(input)?.national ?? "rejected");
from japan_phone import normalize
# Numbers written for callers abroad.
inputs = ["+81-(0)50-3818-1250", "+81 90-1234-5678", "+81-3-5253-8111", "+81 120 123 456", "+810352538111"]
for value in inputs:
number = normalize(value)
print(value, "->", number.national if number else "rejected")
import jp.kurashina.japanphone.JapanPhoneNumber;
import jp.kurashina.japanphone.JapanPhone;
// Numbers written for callers abroad.
String[] inputs = {"+81-(0)50-3818-1250", "+81 90-1234-5678", "+81-3-5253-8111", "+81 120 123 456", "+810352538111"};
for (String input : inputs) {
System.out.println(input + " -> " + JapanPhone.normalize(input).map(JapanPhoneNumber::getNational).orElse("rejected"));
}
Output:
+81-(0)50-3818-1250 -> 050-3818-1250
+81 90-1234-5678 -> 090-1234-5678
+81-3-5253-8111 -> 03-5253-8111
+81 120 123 456 -> rejected
+810352538111 -> rejected