Skip to content

getFullNumberWithPlus() includes national trunk prefixes #149

Closed

Description

@Nilhcem

The CountryCodePicker.getFullNumberWithPlus() method appends a '+' to the countryCode and carrierNumber from user input.

When a user is inputting a phone number including the national trunk prefix, for instance for French (+33) numbers the value '0610101010', the method getFullNumberWithPlus() returns +330610101010 instead of +33610101010.

The first '0' directly after the country code is only used for national calls. International calls with '+33' should remove it.

Hence, the getFullNumberWithPlus() method can return invalid phone numbers.
Here's an example of I expected the getFullNumberWithPlus() to work, using the embedded libphonenumber-android lib:

private fun getExpectedFullNumberWithPlus(context: Context): String {
  val phoneUtil = PhoneNumberUtil.createInstance(context)
  try {
    val countryCode = countryCodePicker.selectedCountryCode
    val defaultRegion = countryCodePicker.selectedCountryNameCode

    var numberToParse = countryCodePicker.fullNumber
    if (numberToParse.startsWith(countryCode)) {
      numberToParse = numberToParse.substring(countryCode.length)
    }

    val phoneNumber = phoneUtil.parse(numberToParse, defaultRegion)
    return "+${phoneNumber.countryCode}${phoneNumber.nationalNumber}"
  } catch (e: NumberFormatException) {
    Timber.e(e, "Error parsing number")
  }
  return countryCodePicker.fullNumberWithPlus
}

Activity

  1. hbb20 commented on Jan 30, 2018

    @hbb20
    Owner

    Thank you for the suggestion. This has been fixed in version 2.1.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions