Forms

Accept mobile numbers only

normalizetype
Use the type to decide whether a number can receive SMS.
Try it
Try 03-5253-8111 or 050-1234-5678.
We will send a code to 090-1234-5678.

How it works

Every result has a type: fixed_line, mobile, ip_phone (050), toll_free (0120 and 0800), or unified_number (0570).

An SMS sign-in form can accept mobile only: the voice mobile numbers that start with 060, 070, 080 or 090. Check the type after normalize instead of matching the first digits yourself.

In each language

import { normalize } from "@kurashina-design/japan-phone";

// An SMS sign-in form accepts voice mobile numbers only.
for (const input of ["090-1234-5678", "070-1000-0000", "03-5253-8111", "050-1234-5678", "0120-123-456"]) {
  const number = normalize(input);
  const verdict = number?.type === "mobile" ? "send a code by SMS" : "ask for a mobile number";
  console.log(`${input} (${number?.type}): ${verdict}`);
}

Output:

090-1234-5678 (mobile): send a code by SMS
070-1000-0000 (mobile): send a code by SMS
03-5253-8111 (fixed_line): ask for a mobile number
050-1234-5678 (ip_phone): ask for a mobile number
0120-123-456 (toll_free): ask for a mobile number