Python phone number validation

phonenumbers 8.13.17

Python version of Google’s common library for parsing, formatting, storing and validating international phone numbers.

Ссылки проекта

Статистика

Метаданные

Лицензия: Apache Software License (Apache License 2.0)

Сопровождающие

Классификаторы

  • Development Status
    • 5 — Production/Stable
    • Developers
    • OSI Approved :: Apache Software License
    • OS Independent
    • Python :: 2
    • Python :: 2.5
    • Python :: 2.6
    • Python :: 2.7
    • Python :: 3
    • Python :: 3.3
    • Python :: 3.4
    • Python :: 3.5
    • Python :: 3.6
    • Python :: 3.7
    • Python :: 3.8
    • Python :: 3.9
    • Python :: 3.10
    • Python :: 3.11
    • Python :: Implementation :: CPython
    • Python :: Implementation :: PyPy
    • Communications :: Telephony

    Описание проекта

    phonenumbers Python Library

    This is a Python port of Google’s libphonenumber library It supports Python 2.5-2.7 and Python 3.x (in the same codebase, with no 2to3 conversion needed).

    Original Java code is Copyright (C) 2009-2015 The Libphonenumber Authors.

    Installation

    Example Usage

    The main object that the library deals with is a PhoneNumber object. You can create this from a string representing a phone number using the parse function, but you also need to specify the country that the phone number is being dialled from (unless the number is in E.164 format, which is globally unique).

    The PhoneNumber object that parse produces typically still needs to be validated, to check whether it’s a possible number (e.g. it has the right number of digits) or a valid number (e.g. it’s in an assigned exchange).

          The parse function will also fail completely (with a NumberParseException ) on inputs that cannot be uniquely parsed, or that can't possibly be phone numbers.

    Once you’ve got a phone number, a common task is to format it in a standardized format. There are a few formats available (under PhoneNumberFormat ), and the format_number function does the formatting.

       If your application has a UI that allows the user to type in a phone number, it's nice to get the formatting applied as the user types. The AsYouTypeFormatter object allows this.

    Sometimes, you’ve got a larger block of text that may or may not have some phone numbers inside it. For this, the PhoneNumberMatcher object provides the relevant functionality; you can iterate over it to retrieve a sequence of PhoneNumberMatch objects. Each of these match objects holds a PhoneNumber object together with information about where the match occurred in the original string.

        You might want to get some information about the location that corresponds to a phone number. The geocoder.area_description_for_number does this, when possible.
     
    
     
    

    For more information about the other functionality available from the library, look in the unit tests or in the original libphonenumber project.

    Memory Usage

    The library includes a lot of metadata, potentially giving a significant memory overhead. There are two mechanisms for dealing with this.

Оцените статью