CountryCodePickerProject icon indicating copy to clipboard operation
CountryCodePickerProject copied to clipboard

leading 0 gets cutoff in phone number

Open mrshinsa opened this issue 4 years ago • 6 comments

Steps to reproduce: Select South Korea as country, enter 01035353535 as the phone number.
getFormattedFullNumber(), getFullNumber() and getFullNumberWithPlus() returns the phone number with leading 0 cutoff. 820035353535

Attached is the screenshot from the sample app: Screenshot_20200423-164840

mrshinsa avatar Apr 23 '20 23:04 mrshinsa

Thanks for reporting. It looks like leading 0 is dropped when making an international call. image

This might not apply to South Korea phone but in national format, Indian phone starts with 0 but that is dropped in international format.

hbb20 avatar Apr 24 '20 01:04 hbb20

Thank you for the information Harsh,

Just out of curiosity, are there any plans to change this? Displaying leading 0 is common practice in Korea, as seen in the below picture. [image: image.png]

If not perhaps, I can look into creating a branch.

Thank you again.

On Thu, Apr 23, 2020 at 6:20 PM Harsh B. Bhakta [email protected] wrote:

Thanks for reporting. It looks like leading 0 is dropped when making an international call. [image: image] https://user-images.githubusercontent.com/4918760/80164769-22493380-8597-11ea-88ce-1a857c2e28bf.png

This might not apply to South Korea phone but in national format, Indian phone starts with 0 but that is dropped in international format.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/hbb20/CountryCodePickerProject/issues/390#issuecomment-618750155, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAVZXL3YCP35YT7LJ4HBT3DRODSNFANCNFSM4MPUYH6Q .

mrshinsa avatar Apr 24 '20 04:04 mrshinsa

@hbb20

I think I've found a way to retrieve the number w/o dropping the leading 0 in the carrier. So basically given the E164 Format of say "+821035353535", the country code will be 82 and the remaining will be carrier number.
https://libphonenumber.appspot.com/phonenumberparser?number=1035353535&country=KR

In order to dispaly the National format of "010-3535-3535", I first disabled the flag: setInternationalFormattingOnly(false) and then formatted to PhoneNumberFormat.NATIONAL :

    public void setFullNumber(String fullNumber) {
        CCPCountry country = CCPCountry.getCountryForNumber(getContext(), getLanguageToApply(), preferredCountries, fullNumber);
        if (country == null)
            country = getDefaultCountry();
        setSelectedCountry(country);
        String carrierNumber = detectCarrierNumber(fullNumber, country);
        try {
            **Phonenumber.PhoneNumber phoneNumber = getPhoneUtil().parse(carrierNumber, country.nameCode);
            String formattedCarrierNumber = getPhoneUtil().format(phoneNumber, PhoneNumberUtil.PhoneNumberFormat.NATIONAL);**
            if (getEditText_registeredCarrierNumber() != null) {
                getEditText_registeredCarrierNumber().setText(formattedCarrierNumber);
                updateFormattingTextWatcher();
            } else {
                Log.w(TAG, "EditText for carrier number is not registered. Register it using registerCarrierNumberEditText() before getFullNumber() or setFullNumber().");
            }

        } catch (NumberParseException e) {
            e.printStackTrace();
        }
    }

Would it be possible to add one more API, say setNationalFullNumber() which would do this?

mrshinsa avatar May 05 '20 05:05 mrshinsa

Upon further examination, simply adding PhoneNumberUtil.PhoneNumberFormat.NATIONAL will not suffice.
InternationalPhoneTextWatcher class does not properly format the number in case 0 is kept in the carrier code.

Still, it would be very useful if we can somehow format the carrier code into National format: :-/

National format 010-3535-3535

mrshinsa avatar May 12 '20 05:05 mrshinsa

Hi, I am using 2.4.6 version of the library. Here is a bug that I want to report. Here is the scenario: lets say that we are in Australia. Our code is +61. I have a contact which has 0431564613. DetectCarrierNumber function detects the "61" from end of the number and takes it as country number and setFullNumber function only sets 3 into my edit text instead of 0431564613. Normally it should detect "61" if it is at the beginning of the number. But it detects "61" even if its in the end of the number and returns carrier number as whatever number we have after 61. Thanks!

fatma12 avatar Mar 02 '21 04:03 fatma12

@mrshinsa @hbb20 was there a fix found for this?

There is a similar issue in Australia whereby the international format for a mobile is like +61412345678 (which is what we would store in our db), however people in Australia are more accustomed to using/seeing the local format like 0412345678.

It would be cool if this library could accept/display either format for UI form input and display, and have it configurable to read the international format (e.g. to store in the db) and also read the local format (e.g. to display in the UI on a user profile page).

PrimeDominus avatar Feb 17 '22 22:02 PrimeDominus