データと保存
E.164 に変換する
normalizeinternational
SMS の送信サービス、CRM、libphonenumber に国際形式で渡します。
試す
0120-123-456 も試してください。着信課金番号には国際表記がありません。
+819012345678
しくみ
international は E.164 形式です。+81 の後に、先頭の 0 を除いた番号が続きます。SMS の送信サービスや CRM の多くがこの形を求めます。libphonenumber もこの形を読めるので、2つのライブラリを並べて使えます。
着信課金(0120・0800)と 0570 には国際形式がありません。international は空です。
各言語で
import { normalize } from "@kurashina-design/japan-phone";
// SMS gateways and CRMs usually expect E.164. libphonenumber reads the same form.
for (const input of ["090-1234-5678", "03-5253-8111", "050-3818-1250", "0120-123-456"]) {
console.log(input, "->", normalize(input).international ?? "(domestic only)");
}
from japan_phone import normalize
# SMS gateways and CRMs usually expect E.164. libphonenumber reads the same form.
for value in ["090-1234-5678", "03-5253-8111", "050-3818-1250", "0120-123-456"]:
print(value, "->", normalize(value).international or "(domestic only)")
import jp.kurashina.japanphone.JapanPhoneNumber;
import jp.kurashina.japanphone.JapanPhone;
// SMS gateways and CRMs usually expect E.164. libphonenumber reads the same form.
for (String input : new String[] {"090-1234-5678", "03-5253-8111", "050-3818-1250", "0120-123-456"}) {
System.out.println(input + " -> " + JapanPhone.normalize(input).get().getInternational().orElse("(domestic only)"));
}
出力:
090-1234-5678 -> +819012345678
03-5253-8111 -> +81352538111
050-3818-1250 -> +815038181250
0120-123-456 -> (domestic only)