Karta.Messaging.Phone (Karta v1.0.0)

Phone numbers as messaging uses them: E.164 (+ and 8 to 15 digits, the first not 0). A number typed the way people write it is normalised with the server's default country (Karta.Messaging.ServerSettings): the customers are on Bonaire (BQ), Curaçao (CW), Aruba (AW), Sint Maarten (SX) and in the Netherlands (NL).

  • +599 777 1234, 00599 777 1234, 599 7771234 (BQ, CW and AW only, where the country code is part of how people write the number) and 777 1234 (the default country is BQ or CW) are +5997771234;
  • 06 12345678 with NL as the country is +31612345678; a single leading 0 is dropped for the countries that write one;
  • spaces, dashes, dots and brackets are ignored.

Anything else is :error. This checks the shape, not whether the number exists.

Summary

Functions

The calling code (digits) of a country, or nil.

The country codes normalise/2 knows.

The countries an E.164 number may be in: those whose calling code starts it, the longest code first (+1721... is Sint Maarten, not the US; +599... is Bonaire or Curaçao). [] for a code Karta does not know.

True when the text is a well-formed E.164 number.

The E.164 form of a number, or :error.

Functions

calling_code(country)

@spec calling_code(String.t()) :: String.t() | nil

The calling code (digits) of a country, or nil.

countries()

@spec countries() :: [String.t()]

The country codes normalise/2 knows.

countries_for(arg1)

@spec countries_for(String.t()) :: [String.t()]

The countries an E.164 number may be in: those whose calling code starts it, the longest code first (+1721... is Sint Maarten, not the US; +599... is Bonaire or Curaçao). [] for a code Karta does not know.

e164?(value)

@spec e164?(term()) :: boolean()

True when the text is a well-formed E.164 number.

normalise(input, default_country \\ "BQ")

@spec normalise(String.t(), String.t()) :: {:ok, String.t()} | :error

The E.164 form of a number, or :error.