Finding numbers in text

Find numbers in a message

extract
Pick every phone number out of a message, in the order it appears.
Try it
090-1234-5678092-513-5612

How it works

extract searches free text and returns one result per number, in the order found. Each result has the same fields as normalize.

  • Any text may surround a number: Japanese words, punctuation, names, line breaks.
  • Digit strings that do not fit the numbering plan or the MIC tables, such as dates, are not returned. Other digit strings, such as order numbers, are returned when they have the length of a phone number and happen to fall in a valid block.
  • The same number written twice is returned twice. See the company page example to remove duplicates.

In each language

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

// A message from a contact form.
const message = "お世話になっております。日中は090-1234-5678、夜は自宅の092-513-5612までご連絡ください。";

for (const number of extract(message)) console.log(number.type, number.national);

Output:

mobile 090-1234-5678
fixed_line 092-513-5612