phone v0.2.1 Phone

Phone is a real telephone number parser, that will help you get useful information from numbers.

How to use

Very simple to use:

iex> Phone.parse("555112345678")
{:ok, %{a2: "BR", a3: "BRA", country: "Brazil", international_code: "55", area_code: "51", number: "12345678"}}

Summary

Functions

Parses a string or integer and returns a map with information about that number

Same as parse(number) but the number doesn’t have the international code, instead you specify country as an atom with two-letters code

Functions

parse(number)

Specs

parse(pos_integer) :: {:ok, Map.t}
parse(String.t) :: {:ok, Map.t}

Parses a string or integer and returns a map with information about that number.

iex> Phone.parse("555112345678")
  {:ok, %{a2: "BR", a3: "BRA", country: "Brazil", international_code: "55", area_code: "51", number: "12345678"}}

  iex> Phone.parse("+55(51)1234-5678")
  {:ok, %{a2: "BR", a3: "BRA", country: "Brazil", international_code: "55", area_code: "51", number: "12345678"}}

  iex> Phone.parse("55 51 1234-5678")
  {:ok, %{a2: "BR", a3: "BRA", country: "Brazil", international_code: "55", area_code: "51", number: "12345678"}}

  iex> Phone.parse(555112345678)
  {:ok, %{a2: "BR", a3: "BRA", country: "Brazil", international_code: "55", area_code: "51", number: "12345678"}}
parse(atom, number)

Specs

parse(Atom.t, pos_integer) :: {:ok, Map.t}
parse(Atom.t, String.t) :: {:ok, Map.t}

Same as parse(number) but the number doesn’t have the international code, instead you specify country as an atom with two-letters code.

For NANP countries you can use the atom :nanp or two-letter codes for any country in NANP.

For United Kingdom is possible to use the more known acronym :uk or the official two-letter code :gb.

iex> Phone.parse(:br, "5112345678")
{:ok, %{a2: "BR", a3: "BRA", country: "Brazil", international_code: "55", area_code: "51", number: "12345678"}}

iex> Phone.parse(:br, "(51)1234-5678")
{:ok, %{a2: "BR", a3: "BRA", country: "Brazil", international_code: "55", area_code: "51", number: "12345678"}}

iex> Phone.parse(:br, "51 1234-5678")
{:ok, %{a2: "BR", a3: "BRA", country: "Brazil", international_code: "55", area_code: "51", number: "12345678"}}

iex> Phone.parse(:br, 5112345678)
{:ok, %{a2: "BR", a3: "BRA", country: "Brazil", international_code: "55", area_code: "51", number: "12345678"}}