giggsey / libphonenumber-for-php

PHP version of Google's phone number handling library
https://giggsey.com/libphonenumber/
Apache License 2.0
4.73k stars 464 forks source link

Missing leading zero CI national phone number ? #495

Closed Fly06-Fr closed 2 years ago

Fly06-Fr commented 2 years ago

Hello, We are experiencing a problem with Ivory Coast mobile numbers. The leading zero is required for both national and international dialing and this is correctly handled by the library when using the format() method. Don't you think that in such a situation, the number returned by the getNationalNumber() method should include the leading zero? (which is not currently the case). Example: https://giggsey.com/libphonenumber/index.php?phonenumber=0789881234&country=CI Many thanks in advance for your reply.

giggsey commented 2 years ago

getNationalNumber() shouldn't be used for formatting. The format() function will handle any leading zeros in the number.

There is a separate function on the PhoneNumber object to return the leading zeros.

On Thu, 3 Mar 2022, 16:21 Fly06-Fr, @.***> wrote:

Hello, We are experiencing a problem with Ivory Coast mobile numbers. The leading zero is required for both national and international dialing and this is correctly handled by the library when using the format() method. Don't you think that in such a situation, the number returned by the getNationalNumber() method should include the leading zero? (which is not currently the case). Example: https://giggsey.com/libphonenumber/index.php?phonenumber=0789881234&country=CI Many thanks in advance for your reply.

— Reply to this email directly, view it on GitHub https://github.com/giggsey/libphonenumber-for-php/issues/495, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACKUQVOMAER6QW3BRATYM3U6DRJXANCNFSM5P26PKAA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you are subscribed to this thread.Message ID: @.***>

Fly06-Fr commented 2 years ago

Hi Joshua and thank for the quick reply.

The leading zero in Ivory Coast mobile phone numbers is not a trunk prefix, it is just the first digit of the two digit operator prefix. Contrary to many others countries, there is no trunk prefix in the Ivory Coast dialing plans.

Hence, the number returned by the getNationalNumber() method for a given CI mobile number should include the leading 0 and be 10 digit long.

giggsey commented 2 years ago

As the Google demo returns the same thing: https://libphonenumber.appspot.com/phonenumberparser?number=0789881234&country=CI, I think you'll need to file an issue with them.

Fly06-Fr commented 2 years ago

Done. I will keep you updated. Thank you.

Fly06-Fr commented 2 years ago

Hi Joshua, The issue has not been accepted as a bug by the google/libphonenumber team.

I got the following answer : _Though the national_number field of parsed proto do not contain 0, the 0s are represented as italian_leading_zero (TRUE) and number_of_leading_zeros (1). Reason: 0s are lost as nationalnumber is a number type field. Please do consider those fields if you need to fetch these details.

The point is that the number returned by the getNationalNumber() method is useless since it is not recognized as a valid number by the library in that case. By digging into the source files, I found the PhoneNumberUtil::getNationalSignificantNumber() method which actually returns the national_number but including the italian leading zeros.

Do you confirm that the relevant number to store into a database is this "national significant number" and not the national_number?

giggsey commented 2 years ago

If you are storing the phone number, I'd be storing E164.

Fly06-Fr commented 2 years ago

This is probably the best solution but for historical reasons we are storing phone numbers by using two fields:

And for the time being I must cope with this design.

Fly06-Fr commented 2 years ago

Do you know which countries other than Italy and Ivory Coast have those leading zeros?

giggsey commented 2 years ago

Not sure. There is a 'leadingZeroPossible' property within the metadata, but that doesn't appear to be used for anything.

Otherwise, PhoneNumberUtil::setItalianLeadingZerosForPhoneNumber() is called at runtime to set it from the national number.

giggsey commented 2 years ago

Are you happy for this issue to now be closed?

webmake commented 2 years ago

We encountered the same issue. Not sure who has resolve it once and for all... Very confusing while trying to validate users input. https://libphonenumber.appspot.com/phonenumberparser?number=%2B3800660000000 this is fine to remove zero but it has italian_leading_zero=false while https://libphonenumber.appspot.com/phonenumberparser?number=%2B2250700000000 has italian_leading_zero=true And at the end both getNationalNumber returns without a zero.

More over https://libphonenumber.appspot.com/phonenumberparser?number=%2B520446000000000 Mexico can have 044 additional digits, but it is italian_leading_zero=false