Home

Awesome

Libphonenumber

Hex.pm

Elixir partial version of libphonenumber by Google. Usage:

Check is phone number (MSISDN)

iex> Libphonenumber.mobile_phone_valid?("+380938562241")
true

iex> Libphonenumber.mobile_phone_valid?("+380338560241")
false

Get phone number info (MSISDN)

iex> Libphonenumber.mobile_phone_number_info("+380938562241")
%{
  country_metadata: %{code: "380", id: "UA", name: "Ukraine (UA)"},
  errors: [],
  phone: "+380938562241",
  valid: true
}

iex> Libphonenumber.mobile_phone_number_info("+380238562241")
%{
  errors: [
    %{'NO PAIRS' => 'Finished'},
    %{"3" => "No country code info found"},
    %{"38" => "No country code info found"},
    %{"380" => "Pattern '(?:50|6[36-8]|7[1-3]|9[1-9])\\d{7}' compilation failed"}
    ],
    valid: false
    }

Installation

The package can be installed by adding libphonenumber to your list of dependencies in mix.exs:

def deps do
  [
    {:libphonenumber, "~> 0.1.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. The docs can be found at https://hexdocs.pm/libphonenumber.