daddyz / phonelib

Ruby gem for phone validation and formatting using google libphonenumber library data
MIT License
1.04k stars 130 forks source link

Problem on parsing numbers that starts with 0685 #218

Open yann120 opened 3 years ago

yann120 commented 3 years ago

Hello,

We have found an edge case bug with the parse function of Phonelib.

Phonelib.parse(number) works fine for every 10 digits french numbers like 0635374637

but with numbers starting with 0685, it have a weird behaviour.

For exemple parsing the number 0685123456 will have this output

[4] pry(main)> Phonelib.parse('0685123456')
=> #<Phonelib::Phone:0x00007f888cf92a88
 @data=
  {"WS"=>
    {:id=>"WS",
     :country_code=>"685",
     :international_prefix=>"0",
     :national=>"123456",
     :format=>{:pattern=>"(\\d+)(\\d{3})(\\d{4})", :format=>"$1 $2 $3"},
     :valid=>[],
     :possible=>[:toll_free, :fixed_line]}},
 @extension="",
 @national_number="123456",
 @original="0685123456",
 @original_s="0685123456",
 @sanitized="0685123456">

It understands that the country code is 685 and the national number 123456

the national number should be 0685123456 and not 123456

Any idea how we could fix this ?

Thanks ! 😄

daddyz commented 3 years ago

@yann120 do you have any way to provide country for phone validator? Or in case you are parsing french phones only you can define default_country for the gem.