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

number works with parse; fails with PhoneNumberMatcher #257

Closed
kalbfled opened this issue Dec 22, 2022 · 2 comments
Closed

number works with parse; fails with PhoneNumberMatcher #257

kalbfled opened this issue Dec 22, 2022 · 2 comments
Labels

Comments

@kalbfled
Copy link

Python version 3.8.10
phonenumbers version 8.13.3

In the Python3 interpreter with parse (as expected):

>>> p.parse('+17553927664', '1')
PhoneNumber(country_code=1, national_number=7553927664, extension=None, italian_leading_zero=None, number_of_leading_zeros=None, country_code_source=0, preferred_domestic_carrier_code=None)
>>> p.parse('+17553927664', 'US')
PhoneNumber(country_code=1, national_number=7553927664, extension=None, italian_leading_zero=None, number_of_leading_zeros=None, country_code_source=0, preferred_domestic_carrier_code=None)

Using PhoneNumberMatcher:

>>> for m in p.PhoneNumberMatcher('asdf 17553927664 ddd', 'US'):
...   print(m)
... 
>>> for m in p.PhoneNumberMatcher('17553927664', 'US'):
...   print(m)
... 

Nothing is printed because there are no matches. With a different phone number, either method correctly parses the input:

>>> p.parse('16502532222', 'US')
PhoneNumber(country_code=1, national_number=6502532222, extension=None, italian_leading_zero=None, number_of_leading_zeros=None, country_code_source=0, preferred_domestic_carrier_code=None)
>>> p.parse('+16502532222', 'US')
PhoneNumber(country_code=1, national_number=6502532222, extension=None, italian_leading_zero=None, number_of_leading_zeros=None, country_code_source=0, preferred_domestic_carrier_code=None)
>>> for m in p.PhoneNumberMatcher('+16502532222', '1'):
...     print(m)
... 
PhoneNumberMatch [0,12) +16502532222

I entered the 755 number in the Java form, as prescribed, and it seems to work.

@daviddrysdale
Copy link
Owner

PhoneNumberMatcher has an additional leniency argument that defaults to only accepting valid numbers (and the example is not valid).

Python 3.7.6 (default, Jan  8 2020, 13:42:34) 
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import phonenumbers as p
>>> x = p.parse('+17553927664', 'US')
>>> p.is_valid_number(x)
False
>>> for m in p.PhoneNumberMatcher('asdf 17553927664 ddd', 'US'):
...     print(m)
... 
>>> for m in p.PhoneNumberMatcher('asdf 17553927664 ddd', 'US', leniency=p.Leniency.POSSIBLE):
...     print(m)
... 
PhoneNumberMatch [5,16) 17553927664

@kalbfled
Copy link
Author

That is useful information. Thank you.

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

No branches or pull requests

2 participants