Forms
Accept pasted labels and notes
normalize
Take the main number from lines like
Try it
03-5253-811103-5253-8111092-513-561203-5253-8112
How it works
People paste numbers with their surroundings. normalize removes what commonly comes with a single number:
- a leading label:
TEL:,FAX:,電話:,電話番号:, in half or full width; - a trailing note:
(代表),(代),(直通), or an extension written with内線.
The result holds the main number only; the extension is not kept. Anything else around the number makes the input invalid. To find numbers in free text, use extract.
In each language
import { normalize } from "@kurashina-design/japan-phone";
// Lines copied from web pages and email signatures.
const pasted = [
"TEL:03-5253-8111(代表)",
"電話番号:03-5253-8111(内線21‐214)",
"Tel: (092(513)5612) (直通)",
];
for (const line of pasted) console.log(normalize(line)?.national);
from japan_phone import normalize
# Lines copied from web pages and email signatures.
pasted = [
"TEL:03-5253-8111(代表)",
"電話番号:03-5253-8111(内線21‐214)",
"Tel: (092(513)5612) (直通)",
]
for line in pasted:
print(normalize(line).national)
import jp.kurashina.japanphone.JapanPhoneNumber;
import jp.kurashina.japanphone.JapanPhone;
// Lines copied from web pages and email signatures.
String[] pasted = {
"TEL:03-5253-8111(代表)",
"電話番号:03-5253-8111(内線21‐214)",
"Tel: (092(513)5612) (直通)",
};
for (String line : pasted) {
System.out.println(JapanPhone.normalize(line).map(JapanPhoneNumber::getNational).orElse(null));
}
Output:
03-5253-8111
03-5253-8111
092-513-5612