Code Monkey home page Code Monkey logo

ex_phone_number's Introduction

ExPhoneNumber

Build Status Module Version Hex Docs Total Download License Last Updated

Elixir library for parsing, formatting, and validating international phone numbers. Based on Google's libphonenumber (current metadata version: v8.12.49).


This README follows develop, which may not be the currently published version.
Here are the docs for the latest published version of ExPhoneNumber.

This branch contains the latest features and often contains versions of the software that are not yet finished or ready to be released.


Installation

Add :ex_phone_number to your list of dependencies in mix.exs:

def deps do
  [
    {:ex_phone_number, "~> 0.3"}
  ]
end

Usage

iex> {:ok, phone_number} = ExPhoneNumber.parse("044 668 18 00", "CH")
{:ok,
 %ExPhoneNumber.Model.PhoneNumber{
   country_code: 41,
   country_code_source: nil,
   extension: nil,
   italian_leading_zero: nil,
   national_number: 446681800,
   number_of_leading_zeros: nil,
   preferred_domestic_carrier_code: nil,
   raw_input: nil
}}

iex> ExPhoneNumber.is_possible_number?(phone_number)
true

iex> ExPhoneNumber.is_valid_number?(phone_number)
true

iex> ExPhoneNumber.get_number_type(phone_number)
:fixed_line

iex> ExPhoneNumber.format(phone_number, :national)
"044 668 18 00"

iex> ExPhoneNumber.format(phone_number, :international)
"+41 44 668 18 00"

iex> ExPhoneNumber.format(phone_number, :e164)
"+41446681800"

iex> ExPhoneNumber.format(phone_number, :rfc3966)
"tel:+41-44-668-18-00"

E164 Formatted Numbers

In E164 formatted numbers the country code can be detected. So you can pass them in to ExPhoneNumber.parse/2 with "" or nil as the second argument.

iex> ExPhoneNumber.parse("+977123456789", "")
{:ok,
 %ExPhoneNumber.Model.PhoneNumber{
   country_code: 977,
   country_code_source: nil,
   extension: nil,
   italian_leading_zero: nil,
   national_number: 123456789,
   number_of_leading_zeros: nil,
   preferred_domestic_carrier_code: nil,
   raw_input: nil
 }}

Copyright and License

Copyright (c) 2016-2021 NLCollect B.V.

The source code is licensed under The MIT License (MIT)

ex_phone_number's People

Contributors

josemrb avatar szymon-jez avatar tomciopp avatar aptinio avatar wojtekmach avatar aerosol avatar zoldar avatar evaneykelen avatar jackburns avatar jerrybels avatar kianmeng avatar stephenlacy avatar sushant12 avatar tomekowal avatar szax avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.