Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation issues for some Australian numbers #292

Closed
superCoderDOM opened this issue Mar 20, 2024 · 3 comments
Closed

Validation issues for some Australian numbers #292

superCoderDOM opened this issue Mar 20, 2024 · 3 comments

Comments

@superCoderDOM
Copy link

We are escalating this to you as our FE validation (javascript) accepts the number, but our Python backend raises a validation error. This is blocking one of our customers from updating their profile.

After successfully parsing the E164 string "+61461271797", an Australian (AU) mobile phone number, the call to phonenumbers.is_valid_number() with the parsed number returns False.

The validation for this Australian number succeeds on Google's Java version:
https://libphonenumber.appspot.com/phonenumberparser?number=%2B61461271797&country=AU

The issue occurs on the latest version v8.13.32 but is present much further back. We tested down to v8.12.33 and it still returns False when testing for validity.

Here is a code snippet reproducing the issue when passed the number above:

import phonenumbers

def check_phone_number(phone_number):
    """
    Phone number validation uses the python port of Google's libphonenumber library
    This function requires the phone number to arrive in a parseable international format.
    The returned value is provided in E164 format.
    """

    if phone_number == "":
        return

    try:
        parsed_number = phonenumbers.parse(phone_number)
    except phonenumbers.NumberParseException:
        raise BaseException("Not a valid E164 phone number")

    if phonenumbers.is_valid_number(parsed_number):
        formatted_number = phonenumbers.format_number(
            parsed_number, phonenumbers.PhoneNumberFormat.E164
        )
        if phone_number == formatted_number:
            return

    raise BaseException("Not a valid phone number")
@daviddrysdale
Copy link
Owner

Odd, it works for me:

Python 3.11.7 (main, Dec  8 2023, 14:22:46) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import phonenumbers
>>> parsed_number = phonenumbers.parse("+61461271797")
>>> phonenumbers.is_valid_number(parsed_number)
True
>>> phonenumbers.format_number(parsed_number, phonenumbers.PhoneNumberFormat.E164)
'+61461271797'
>>> phonenumbers.__version__
'8.13.32'

@daviddrysdale
Copy link
Owner

Same result with an old Python 2 on a different OS (below). Is there any chance your library install has local modifications somehow?

Python 2.7.18 (default, May 10 2022, 12:54:30) 
[GCC Apple LLVM 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import phonenumbers
>>> parsed_number = phonenumbers.parse("+61461271797")
>>> phonenumbers.is_valid_number(parsed_number)
True
>>> phonenumbers.format_number(parsed_number, phonenumbers.PhoneNumberFormat.E164)
u'+61461271797'
>>> phonenumbers.__version__
'8.13.32'

@superCoderDOM
Copy link
Author

@daviddrysdale Thanks for the quick replies. I was also able to reproduce your steps locally and got the expected validation boolean back. That made me go back to the developer who reported the issue to me and we figured out that the tests he ran were in an old container running an older version of the package.
It's all sorted, sorry for the waste of time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants