catamphetamine / libphonenumber-js

A simpler (and smaller) rewrite of Google Android's libphonenumber library in javascript
https://catamphetamine.gitlab.io/libphonenumber-js/
MIT License
2.79k stars 216 forks source link

Leading Double 00 in Country Code #185

Closed 360disrupt closed 4 years ago

360disrupt commented 6 years ago
libphonenumber-js: v 1.0.24
node v7.10.1

I don't get the same result/format a number to E.164 for +49 and 0049?

libphonenumber.parse( '0049(89) 11196611' ) //returns {}
libphonenumber.parse( '0049(89) 11196611' , 'DE') //returns {}
new libphonenumber.AsYouType('DE').input('0049(89) 11196611') //'00498912196611'
libphonenumber.parse( '0049(89) 11196611' ) //returns {}
libphonenumber.parse( '0049(89) 11196611' , 'DE') //returns {}
new libphonenumber.AsYouType('DE').input('0049(89) 11196611') //'00498912196611'

The same number libphonenumber.appspot.com Is correctly trnaformed to E.164

Is there are reason why a leading 00 is not equal to a +? Or can it be safely tranformed:

let tel =  '0049(89) 11196611'.replace(/^00/, '+')
let parsedNumber = libphonenumber.parse(tel)
if (parsedNumber.phone)
  libphonenumber.format(parsedNumber.phone,  parsedNumber.country, 'E.164')
catamphetamine commented 6 years ago

This library currently doesn't support "dial out codes" as stated in the README. https://en.wikipedia.org/wiki/List_of_international_call_prefixes I'm not sure if it should. Who would need to input a phone number as 00498912196611 instead of +498912196611. I think such use-cases are non-existent.

360disrupt commented 6 years ago

I wouldn't be 100% sure about this I could imagine users typing numbers into forms like they are used to dial them. But the regex replace shouldn't work then, if the prefix isn't 00 everywhere.

catamphetamine commented 6 years ago

I wouldn't be 100% sure about this I could imagine users typing numbers into forms like they are used to dial them

I don't think it would make any sense in a form beause in a form user either enters his local number or his number in international format (+...). Anyway, I'm closing this issue for now. If someone finds a valid use-case where IDD prefix is required then I might consider reopening this issue and adding this feature to the library.

dcustodio commented 4 years ago

someone finds a valid use-case where IDD prefix is required then I might consider reopening this issue and adding this feature to the library..

For the record, I am using this package (which I am very thankful for) to validate user input phone numbers. I use the parsePhoneNumberFromString to get the phone number from inside whatever sentence they type. The website is international and we don't ask for the user's country so I cannot set a default country. We noticed that a reasonable amount of users chooses to use 00 instead of + thus the parsePhoneNumberFromString fails to recognize the number. The quick solution is to replace the 00 with a + before parsing, but it would be a nice to have if the library would accept it.

catamphetamine commented 4 years ago

@dcustodio

We noticed that a reasonable amount of users chooses to use 00 instead of +

Oh really? Lol. Okay, I'll reopen this one.

dcustodio commented 4 years ago

yes, don't ask me why. Maybe they are browsing the website in a mobile and it's easier to press 00 than long-press to get a +...

catamphetamine commented 4 years ago

@360disrupt Let's start with your case. You seem to have reported it a long time ago, and the issue seems to have been fixed since then:

Demo result:

image

Google's demo result

So I guess parsePhoneNumberFromString() works.

About AsYouType then. It doesn't seem to work:

image

I'll see if that could be fixed.

Now, @dcustodio 's case. Provide an exact case when the library's parsePhoneNumberFromString result differs from Google's demo result. P.S.: for searching multiple numbers in text use findPhoneNumbersInText() function.

catamphetamine commented 4 years ago

Interestingly, this one turned out to be quite simple. Released libphonenumber-js@1.7.44. Closing.