View Source SmsUp.Numbers.PhoneValidator (sms_up v1.3.4)
This module provides function to validate phone number formats.
Summary
Functions
Format the given number to international format.
Check if the number seems to be valid format wise.
Functions
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"}
@spec 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