Code Monkey home page Code Monkey logo

ex_phone_number's People

Contributors

aerosol avatar aptinio avatar evaneykelen avatar jackburns avatar jerrybels avatar josemrb avatar kamilkowalski avatar kianmeng avatar martinthenth avatar stephenlacy avatar sushant12 avatar szymon-jez avatar tomciopp avatar tomekowal avatar trod avatar wojtekmach avatar zediogoviana avatar zoldar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ex_phone_number's Issues

Patch Release

Can you release a new patch version instead of recommending using a reference to the git repo? The last few commits should be fine to be bundled into a 0.1.1 release without worrying about anything breaking.

Publish to Hex

Thank you for your work on porting libphonenumber. We've been using it within our project with great success. Is is possible however to publish this package to Hex.pm?

Update PhoneNumberMetadata

Refs #42, #39, #33

Problem

The library uses outdated metadata. Therefore it is not validating/formatting some numbers right.

Solution

To upgrade the metadata it is also necessary to upgrade the code.

Add License

I'm guessing Apache 2.0 (which most Elixir projects seem to use) or MIT.

Argentina(AR) number formatting and validation errors

I've been using this library for a few years, but there are errors to format and validate Argentina numbers.

A formatted national number of AR by the library is invalid and not formatted again properly.
The only difference of result is 'italian_leading_zero: true' at second formatting.

Could you check it? Thanks. :)

Initial formatting

iex> {:ok, phone_number} = ExPhoneNumber.parse("+54 114321-1200", "AR")
{:ok,
 %ExPhoneNumber.Model.PhoneNumber{
   country_code: 54,
   country_code_source: nil,
   extension: nil,
   italian_leading_zero: nil,
   national_number: 1143211200,
   number_of_leading_zeros: nil,
   preferred_domestic_carrier_code: nil,
   raw_input: nil
 }}

iex> ExPhoneNumber.format(phone_number, :national)
"011 4321-1200"

iex> ExPhoneNumber.is_valid_number?(phone_number)
true

Second formatting

iex> {:ok, phone_number} = ExPhoneNumber.parse("011 4321-1200", "AR")
{:ok,
 %ExPhoneNumber.Model.PhoneNumber{
   country_code: 54,
   country_code_source: nil,
   extension: nil,
   italian_leading_zero: true,
   national_number: 1143211200,
   number_of_leading_zeros: nil,
   preferred_domestic_carrier_code: nil,
   raw_input: nil
 }}

iex> ExPhoneNumber.format(phone_number, :national)
"01143211200"

iex> ExPhoneNumber.is_valid_number?(phone_number)
false

Add support for new metadata

Seeing as the metadata used by this library is three years old and Google is making metadata changes rather frequently is it possible that you could add support for the new metadata files? I tried your instructions in #22.

You can try to:

  1. Replace this file from the ex_phone_number repository with this file from google libphonenumber.
  2. Test if it works.
  3. Add create a pull request here with the changes from point 1. We are welcome to update this.

But it 132/438 tests failed when doing so.

Return country code from given phone number

Hi, this is a doubt not an issue, I see that the Ruby implementation return the country code from a given phone number, like this:

number = GlobalPhone.parse('+1-312-555-1212')
# => #<GlobalPhone::Number territory=#<GlobalPhone::Territory country_code=1 name=US> national_string="3125551212">

Does this Elixir implementation return the same? I couldn't get this info, not even in tests.

Thanks!

Doesn't handle short codes properly

This library doesn't appear to handle short codes properly.

Check this case:

iex(1)> {:ok, phone_number} = ExPhoneNumber.parse("88811", "US")        
{:ok,
 %ExPhoneNumber.Model.PhoneNumber{
   country_code: 1,
   national_number: 88811,
   extension: nil,
   italian_leading_zero: nil,
   number_of_leading_zeros: nil,
   raw_input: nil,
   country_code_source: nil,
   preferred_domestic_carrier_code: nil
 }}
iex(2)> ExPhoneNumber.is_valid_number?(phone_number)
false

That is a valid shortcode, from which I received a confirmation code.

I'd be willing to take this on. A little guidance on where to read the code to port from in libphonenumber, and where it should go in ex_phone_number would be super helpful.

Patch release

Any possibility of cutting a new release with the updated dependencies?

Stack smashing when compiling metadata.ex

I am running erlang 1:18.2 and Elixir 1.2.4 on a VirtualBox with 2GB of memory. When I try to compile this project, I get

Crash dump is being written to: erl_crash.dump...*** stack smashing detected ***: /usr/lib/erlang/erts-7.2/bin/beam terminated

Typically this can be caused by memory pressure on the VM, but mem shows 600MB free at the time of the crash.

Unsafe dependency

Hi,

One of the dependency is not safe according to mix deps.audit. Here is the full output of the command :

Name: sweet_xml
Version: 0.6.6
Lockfile: /home/runner/work/app/app/mix.lock
CVE: 2019-15160
URL: https://github.com/kbrw/sweet_xml/issues/71
Title: Inline DTD allows XML bomb attack
Patched versions: >= 0.7.0

Vulnerabilities found!

Would it be possible to update that dependency and create a current release ?

French phone number is_possible_number? true for US country code

iex(18)> {:ok, a} = ExPhoneNumber.parse("07 64 01 94 08 ", "US")
{:ok,
 %ExPhoneNumber.Model.PhoneNumber{
   country_code: 1,
   country_code_source: nil,
   extension: nil,
   italian_leading_zero: true,
   national_number: 764019408,
   number_of_leading_zeros: nil,
   preferred_domestic_carrier_code: nil,
   raw_input: nil
 }}
iex(19)> a |> ExPhoneNumber.is_possible_number?()              
true

764019408 as a 9 digit number could physically never be a possible US phone number.

What exactly does is_possible_number? check for?

Update version

Hi, first of all thanks for this library. Do you have plan to release newer version with updated dependencies and some validations soon?

thanks

Cache XML in ETS

Hi,

I just had a quick look through library and please correct me if I'm wrong but it seems that ex_phone_number reads & parses xml file on every function call.

If this is the case and there are enough resources at your disposal it would be nice to load & parse XML only once and query it directly from memory.

Release new hex version?

Hello!

I can see that the latest hex release is from 2020. There a lot of changes since then in the develop branch.

Any plans to release that?

Validating US numbers with area code 689

Hi, thank you for the helpful library you've built.

I stumbled upon a problem validating US phone numbers with area code 689 which seems to be a fairly new (several years old) phone area code for somewhere in Florida, at least according to this article.

When I test at https://libphonenumber.appspot.com with a number such as +16894023931 it validates it successfully, but this returns false:

> {:ok, parsed_phone} = ExPhoneNumber.parse("+16894023931", "US")
> ExPhoneNumber.is_valid_number?(parsed_phone)
false

Adding a Changelog

It would be a nice to have a summary for any breaking changes that need to be rectified between version changes. It looks like a minor version was bumped today for formatting the codebase but I haven't checked to see if there were any API updates. A changelog would be a welcome addition.

no function clause matching error??

Lets say i have changeset like follow

def changeset_user_register(struct, params \%{}) do
struct
|> cast(params, [:name, :email, :countryCode, :phone])
|> validate_required(:name, [message: "Name Must Not Be Empty"])
|> validate_required(:countryCode, [message: "countryCode Must Not Be Empty"])
|> validate_required(:phone, [message: "Phone Number Must Not Be Empty"])
|> valid_phone_number
end

I am trying to validate number is valid or not so created custom validation like follow
'

defp valid_phone_number(struct) do
countryCode = get_field(struct, :countryCode)
phone = get_field(struct, :phone)
{result, phone_number} = ExPhoneNumber.parse(phone, countryCode)
if ExPhoneNumber.is_valid_number?(phone_number) do
struct
else
add_error(struct, :phone, "invalid number")
end
struct
end

When is run the application it shows no function clause matching in ExPhoneNumber.is_valid_number?/1

what mistake i made here?

PhoneNumberMetadata is out of date

Hi all,

We noticed PhoneNumberMetadata to be out of date for Mexican numbers. We updated a fork with the Mexican metadata, but we'd love to help maintain this library.

Happy to open a PR. Should we update just the mexican data (like we did in our fork) or the entire file? Does the community have a preference?

Publish Latest Version to Hex

Updates to the PhoneNumberMetadata.xml have not been published to Hex.pm which is causing validation errors when the phone number is actually valid. For example, US area code 689 is not valid in version 0.2.1 from Hex.

Update from 0.3.0 to 0.4.0 fails due to Tesla

Hey folks

When we update this lib from version 0.3.0 to 0.4.0 it fails due to Tesla.

==> ex_phone_number
Compiling 22 files (.ex)

== Compilation error in file lib/ex_phone_number/mix/tasks/update_metadata.ex ==
** (CompileError) lib/ex_phone_number/mix/tasks/update_metadata.ex:11: module Tesla is not loaded and could not be found
    (elixir 1.14.3) expanding macro: Kernel.use/1
    lib/ex_phone_number/mix/tasks/update_metadata.ex:11: Mix.Tasks.UpdateMetadata.GitHub (module)
could not compile dependency :ex_phone_number, "mix compile" failed. Errors may have been logged above. You can recompile this dependency with "mix deps.compile ex_phone_number", update it with "mix deps.update ex_phone_number" or clean it with "mix deps.clean ex_phone_number"

This dependency is declared in the lib, but only on dev and test, so I believe it's only installed on the lib development and testing, but not when it's imported in other project. Is this indented?

My project also has Tesla, but I believe it's compiled later by mix.

This is how the dependency is on mix.lock:

"ex_phone_number": {:hex, :ex_phone_number, "0.4.0", "2f9945be9f09bc892f9d50a504669dbe2cd590eb64ed110a2d8dbc551878337a", [:mix], [{:sweet_xml, "~> 0.7", [hex: :sweet_xml, repo: "hexpm", optional: false]}], "hexpm", "1a78506a19ee1d7bee511c81a8be35cca23053e519d6f47354926bd302aa202f"},

Disable debugging when compiling as dependency

When ex_phone_number is included into a project, it generates a lot of noise when compiling for the first time:

17:39:40.286 [debug] region_code: "SZ"

17:39:40.286 [debug] has not national_prefix

17:39:40.286 [debug] national_prefix_formatting_rule: ""

17:39:40.286 [debug] carrier_code_formatting_rule: ""

17:39:40.286 [debug] available_formats count: 1

17:39:40.287 [debug] ---> number_format

(...)

while this might be helpful when actively developing the library, this should be disabled by default when using it elsewhere.

Improve docs for all the main functions

As of now, Hex docs are empty for the functions. Although docs and some of the example usage is already present in the README, it would be nice to have the same and more on the hexdocs.

Get region from number

Hi, I was looking to get the region (or region code) from a number, and was wondering if you would be open to pull requests for such a feature, and if so, how to structure it.

Getting warning on Elixir 1.3.2

Unsafe variable found at:
  lib/ex_phone_number/metadata/phone_metadata.ex:191

warning: the variable "phone_metadata" is unsafe as it has been set inside a case/cond/receive/if/&&/||. Please explicitly return the variable value instead. For example:

    case int do
      1 -> atom = :one
      2 -> atom = :two
    end

should be written as

    atom =
      case int do
        1 -> :one
        2 -> :two
      end

cc @josemrb

schema and embedded_schema discrepancies

I was redirected here from elixir-ecto/ecto#4383 by @josevalim

Correct. You must file a bug in ExPhoneNumber, since it should be able to handle the value it loads in cast. I will improve the docs here.

I will just paste the bug description I posted there:

We use EctoPhoneNumber to store fields in the database. This validates the data, but it can get invalidated when obfuscating.
With ecto schema backed by db when I have a field:
field(:contact_number, EctoPhoneNumber) it loads the invalid data still fine.

Repo.get(Customer, 2929) |> Map.get(:contact_number)
#EctoPhoneNumber<14111111111>

Even when it's not valid

CustomersCore.LegacyRepo.all("customers" |> where([c], c.id == 2929) |> select([c], c.contact_number)) |> hd()
"14111111111"
"customers" |> where([c], c.id == 2929) |> select([c], c.contact_number) |> CustomersCore.LegacyRepo.all() |> hd() |> EctoPhoneNumber.cast()
:error

My problem is that I created an embedded schema for use with elastic search that has the same data and field definition and it fails when loading with Ecto.embedded_load.

Ecto.embedded_load(Customer, customer["_source"], :json)
** (ArgumentError) cannot load `"14111111111"` as type EctoPhoneNumber for field `contact_number` in schema CustomersCore.Schemas.Legacy.Customer
    (ecto 3.11.1) lib/ecto/schema/loader.ex:76: anonymous fn/5 in Ecto.Schema.Loader.unsafe_load/4
    (elixir 1.16.1) lib/enum.ex:2528: Enum."-reduce/3-lists^foldl/2-0-"/3
    iex:24: (file)
    ```

### Expected behavior

I would expect that schema and embedded schema behave in the same way.

Mix deps.get can't fetch the library

I am running Elixir 1.3.1 and it gave me the following error message: error: pathspec 'origin/master' did not match any file(s) known to git.

I believe it is because the master branch has been deleted and replaced with develop.

Release versions

Thanks for the great package.

Would it be possible to make frequent releases, for example when the metadata is updated? This would make it easier to manage this dependency in other projects.

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.