SmsUp.Numbers.PhoneValidator (sms_up v1.0.2) View Source

This module provides function to validate phone number formats.

Link to this section Summary

Functions

Format the given number to international format.

Check if the number seems to be valid format wise.

Link to this section Functions

Link to this function

format(number, country_code)

View Source

Specs

format(String.t(), String.t()) :: {:ok, String.t()} | {:error, String.t()}

Format the given number to international format.

Returns a ok tupple with the formated number or an erro tupple and the reason.

Examples

iex> SmsUp.Numbers.PhoneValidator.format("+41765556677", "CH")
{:ok, "+41765556677"}

iex> SmsUp.Numbers.PhoneValidator.format("0765556677", "CH")
{:ok, "+41765556677"}

iex> SmsUp.Numbers.PhoneValidator.format("765556677", "CH")
{:ok, "+41765556677"}

iex> SmsUp.Numbers.PhoneValidator.format("0630772288", "FR")
{:ok, "+33630772288"}

iex> SmsUp.Numbers.PhoneValidator.format("0630772288", "ZZ")
{:error, "Invalid country calling code"}

iex> SmsUp.Numbers.PhoneValidator.format("Hello", "FR")
{:error, "The string supplied did not seem to be a phone number"}
Link to this function

is_valid_number?(number)

View Source

Specs

is_valid_number?(String.t()) :: true | false

Check if the number seems to be valid format wise.

Returns true or false.

Examples

iex> SmsUp.Numbers.PhoneValidator.is_valid_number?("+41765556677")
true

iex> SmsUp.Numbers.PhoneValidator.is_valid_number?("0765556677")
false

iex> SmsUp.Numbers.PhoneValidator.is_valid_number?("555")
false

iex> SmsUp.Numbers.PhoneValidator.is_valid_number?("hello")
false