floere / phony

E164 international phone number normalizing, splitting, formatting.
http://florianhanke.com/phony/
MIT License
1.01k stars 226 forks source link

plausible? method returns false on numbers with cc (but normalize works) #382

Closed callmeed closed 2 years ago

callmeed commented 7 years ago

What I did

irb> phone = '(310) 555-2121' => "(310) 555-2121" irb> cc = '1' => "1" irb> Phony.plausible?(phone, cc: cc) => false irb> Phony.normalize(phone, cc: cc) => "13105552121"



What happened
-------------

* The `.plausible?` method returned `false` even though calling `normalize` works when specifying the cc.

What I expected to happen and why
---------------------------------

* The Normalize docs explicitly state to use `.plausible?` before normalizing
* It stands to reason that `.plausible?` should accept a cc param just like `normalize` and return the proper bool value
floere commented 7 years ago

Thanks for the nice writeup, Erik!

The issue here is that plausible? uses the cc parameter differently - it reduces the possibility that a number is plausible to only the numbers which have a certain cc. The first example in the plausible? docs shows this.

I noticed that there should be an accompanying text explaining this more clearly, sorry about that!

So you should be able to use both and not use the cc parameter with plausible?. Does that help?

On Tuesday, 27 June 2017, Erik Dungan notifications@github.com wrote:

What I did

  • Tried to validate a number + cc using the .plausible? method before normalizing

irb> phone = '(310) 555-2121' => "(310) 555-2121" irb> cc = '1' => "1" irb> Phony.plausible?(phone, cc: cc) => false irb> Phony.normalize(phone, cc: cc) => "13105552121"

What happened

  • The .plausible? method returned false even though calling normalize works when specifying the cc.

What I expected to happen and why

  • The Normalize docs explicitly state to use .plausible? before normalizing
  • It stands to reason that .plausible? should accept a cc param just like normalize and return the proper bool value

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/floere/phony/issues/382, or mute the thread https://github.com/notifications/unsubscribe-auth/AAALzm78g2LsOJptz3nwTw3-8rqvAvA_ks5sIVXVgaJpZM4OHEoz .

dsgraham commented 5 years ago

The plausible? method still doesn't do what one would expect. It seems to only return true if the phone number string includes the country code.

[8] pry(main)> Phony.plausible?('616-123-4574')
=> false
[9] pry(main)> Phony.plausible?('616-123-4574', cc: '1')
=> false
[10] pry(main)> Phony.plausible?('1-616-123-4574', cc: '1')
=> true
[11] pry(main)> Phony.plausible?('1-616-123-4574')
=> true

Shouldn't all of those return true?