View Source LivePhone.Util (live_phone v0.7.0)

Link to this section Summary

Functions

Parses the given country_code into an emoji, but I should note that the emoji is not validated so it might return an invalid emoji (this will also depend on the unicode version supported by your operating system, and which flags are included.)

This is used to try and get a Country for a given phone number.

This is used to normalize a given phone number to E.164 format, and returns a tuple with {:ok, formatted_phone} for valid numbers and {:error, unformatted_phone} for invalid numbers.

This is used to verify a given phone number and see if it is a valid number according to ExPhoneNumber.

Link to this section Functions

Link to this function

emoji_for_country(country_code)

View Source
@spec emoji_for_country(String.t() | nil) :: String.t()

Parses the given country_code into an emoji, but I should note that the emoji is not validated so it might return an invalid emoji (this will also depend on the unicode version supported by your operating system, and which flags are included.)

examples

Examples

iex> Util.emoji_for_country(nil)
""

iex> Util.emoji_for_country("US")
"πŸ‡ΊπŸ‡Έ"
@spec get_country(String.t()) ::
  {:ok, LivePhone.Country.t()} | {:error, :invalid_number}

This is used to try and get a Country for a given phone number.

examples

Examples

iex> Util.get_country("")
{:error, :invalid_number}

iex> Util.get_country("+1555")
{:error, :invalid_number}

iex> Util.get_country("+1555")
{:error, :invalid_number}

iex> Util.get_country("+1 (555) 555-1234")
{:error, :invalid_number}

iex> Util.get_country("+1 (555) 555-1234")
{:error, :invalid_number}

iex> Util.get_country("+1 (650) 253-0000")
{:ok, %LivePhone.Country{code: "US", flag_emoji: "πŸ‡ΊπŸ‡Έ",
  name: "United States of America (the)", preferred: false, region_code: "1"}}

iex> Util.get_country("+16502530000")
{:ok, %LivePhone.Country{code: "US", flag_emoji: "πŸ‡ΊπŸ‡Έ",
  name: "United States of America (the)", preferred: false, region_code: "1"}}
Link to this function

normalize(phone, country)

View Source
@spec normalize(String.t(), String.t()) :: {:ok, String.t()} | {:error, String.t()}

This is used to normalize a given phone number to E.164 format, and returns a tuple with {:ok, formatted_phone} for valid numbers and {:error, unformatted_phone} for invalid numbers.

examples

Examples

iex> Util.normalize("1234", nil)
{:error, "1234"}

iex> Util.normalize("+1234", nil)
{:ok, "+1234"}

iex> Util.normalize("+1 (650) 253-0000", "US")
{:ok, "+16502530000"}
@spec valid?(String.t()) :: boolean()

This is used to verify a given phone number and see if it is a valid number according to ExPhoneNumber.

examples

Examples

iex> Util.valid?("")
false

iex> Util.valid?("+1555")
false

iex> Util.valid?("+1555")
false

iex> Util.valid?("+1 (555) 555-1234")
false

iex> Util.valid?("+1 (555) 555-1234")
false

iex> Util.valid?("+1 (650) 253-0000")
true

iex> Util.valid?("+16502530000")
true