Sanitize, validate and format phone numbers into E.164 valid phone numbers.
Project description
py-phone-number-fmt
Sanitize, validate and format phone numbers into E.164 valid phone numbers.
Google's libphonenumber on steroids. Tries all sorts of crazy combinations in an attempt to create a valid phone number. Useful for those of us who have to deal with poorly sanitized data.
Installation
$ pip install py-phone-number-fmt
Usage
Retrieve first valid number
from phonenumberfmt import format_phone_number
# implied phone region is the country of which to
# use the dialing prefix in case the number appears
# to be local
result = format_phone_number('778\173 0.92', implied_phone_region='RO')
assert result == '+40778173092'
Retrieve all valid numbers
# implied phone region is the country of which to
# use the dialing prefix in case the number appears
# to be local
result = format_phone_number_list('+40773818041 / +97172273000', implied_phone_region='RO')
assert result == ['+40778173092', '+97172273000']
The resulting phone number will be formatted according to the E.164 standard. Want to change the output format? Pass the third, optional parameter fmt
with a valid member of phonenumbers.NumberFormat
:
from phonenumbers import NumberFormat
result = format_phone_number(
'778\173 0.92',
implied_phone_region='RO',
fmt=NumberFormat.INTERNATIONAL, # default is NumberFormat.E164
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file py-phone-number-fmt-2.0.0.tar.gz
.
File metadata
- Download URL: py-phone-number-fmt-2.0.0.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ca9f3d11dc7292d5f156487a734c6265011585354b40de5aae09ca622c390fb |
|
MD5 | 6532395ef171d879e634cafa1c7782c5 |
|
BLAKE2b-256 | d71d2a4274b53675962d19913f9480595eb2c8d60d68d8a9a190116e73f5c14d |
File details
Details for the file py_phone_number_fmt-2.0.0-py3-none-any.whl
.
File metadata
- Download URL: py_phone_number_fmt-2.0.0-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aeffae50889884269c14ed95e8f1df97a37db2bf3f917850aef8a1258c5b9a5a |
|
MD5 | 6aaeaa327813d38d65b288f9fbec96de |
|
BLAKE2b-256 | cf760678c5ff0b54a211860e10dc94e0f7ad8fc6ba524ebb4e49a58c27df0953 |