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
Close
Hashes for py-phone-number-fmt-1.2b2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5935ecf9f0dd5c34681e33a4f4b1db00ab872b59dbb55459c513b790b9c5cfc2 |
|
MD5 | 60e6d1c844b3c3d64bf280793dd0b66d |
|
BLAKE2b-256 | c395f021b678aa7e555ee8983f269bcd33dd349ab1862edc49211b70806fb296 |
Close
Hashes for py_phone_number_fmt-1.2b2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7238b5a6f1bde66c59ca96c20b68b5ad774421df5a91333934acd1971c562301 |
|
MD5 | 5ccaa8d117dca6686f8896f11c08676a |
|
BLAKE2b-256 | 07c8d3571071a6a5d9959c599f3ca6a4ee1480caa74d2fb38780aa758ac0916e |