Giter Club home page Giter Club logo

Comments (4)

volisoft avatar volisoft commented on August 22, 2024

That's interesting. For this example it returns only last matched number, however it can parse both numbers well

text = "Call me at (067) 97-28-961  r on 097922458 after 10am."
for match in phonenumbers.PhoneNumberMatcher(text, "UA"):
    print(match)

Returns: 097922458

text = "Call me at (067) 97-28-961   after 10am."
for match in phonenumbers.PhoneNumberMatcher(text, "UA"):
    print(match)

Returns: (067) 97-28-961

from python-phonenumbers.

daviddrysdale avatar daviddrysdale commented on August 22, 2024

For your first example you need to change the leniency of the matcher; the first number is possible but not valid as a Russian number, and the second number is neither possible nor valid:

>>> text = "Call me at (067) 97-28-961  r on 097922458 after 10am."
>>> x = phonenumbers.parse("0679728961", "RU")
>>> phonenumbers.is_valid_number(x)
False
>>> phonenumbers.is_possible_number(x)
True
>>> y = phonenumbers.parse("097922458", "RU")
>>> phonenumbers.is_valid_number(y)
False
>>> phonenumbers.is_possible_number(y)
False
>>> for match in phonenumbers.PhoneNumberMatcher(text, "RU", leniency=phonenumbers.Leniency.POSSIBLE):
...   print(match)
... 
PhoneNumberMatch [11,26) (067) 97-28-961

For your second example, as Ukrainian numbers the first number is valid and the second number is possible-but-not-valid:

>>> text = "Call me at (067) 97-28-961  r on 097922458 after 10am."
>>> text2 =  "Call me at (067) 97-28-961   after 10am."
>>> x = phonenumbers.parse("0679728961", "UA")
>>> phonenumbers.is_valid_number(x)
True
>>> y = phonenumbers.parse("097922458", "UA")
>>> phonenumbers.is_valid_number(y)
False
>>> phonenumbers.is_possible_number(y)
True
>>> for match in phonenumbers.PhoneNumberMatcher(text, "UA"):
...     print(match)
... 
PhoneNumberMatch [11,26) (067) 97-28-961
>>> for match in phonenumbers.PhoneNumberMatcher(text2, "UA"):
...     print(match)
... 
PhoneNumberMatch [11,26) (067) 97-28-961
>>> for match in phonenumbers.PhoneNumberMatcher(text, "UA", leniency=phonenumbers.Leniency.POSSIBLE):
...     print(match)
... 
PhoneNumberMatch [11,26) (067) 97-28-961
PhoneNumberMatch [33,42) 097922458
>>> for match in phonenumbers.PhoneNumberMatcher(text2, "UA", leniency=phonenumbers.Leniency.POSSIBLE):
...     print(match)
... 
PhoneNumberMatch [11,26) (067) 97-28-961

from python-phonenumbers.

TheDevelolper avatar TheDevelolper commented on August 22, 2024

020 7851 7813 Doesn't work for me!

for match in phonenumbers.PhoneNumberMatcher(text, "gb", phonenumbers.Leniency.POSSIBLE):
    n = phonenumbers.format_number(match.number, phonenumbers.PhoneNumberFormat.INTERNATIONAL)
    print(n)

from python-phonenumbers.

daviddrysdale avatar daviddrysdale commented on August 22, 2024

@kiranshub , this issue was closed over two and half years ago -- please could you raise a separate issue with more details of what isn't working for you (including library version etc.).

from python-phonenumbers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.