Skip to main content

Library to get canonical phone number

Project description

Canonical Phone

Purpose

Convert given phone number into a string with hiphenated phone number with country code. Default is assumed to be Indonesian number.

Installation

pip install canonical-phone==0.0.10

How to use?

When country code is unknown

from canonical_phone.phone import canonical_number
phone_no = canonical_number(phone) # If invalid, returns False
if not phone_no:
    raise Exception("invalid phone number")

With country code

from canonical_phone.phone import canonical_number
phone_no = canonical_number(phone, has_country_code=True) # If invalid, returns False
if not phone_no:
    raise Exception("invalid phone number")

Input/Output Combinations

    [
        {
            "input": "62-8734878374",
            "output": "62-8734878374",
        },
        {
            "input": "628734878374",
            "output": "62-8734878374",
        },
        {
            "input": "8734878374",
            "output": "62-8734878374",
        },
        {
            "input": "84-8734878374",
            "output": "84-8734878374",
        },
        {
            "input": "91-8734878374",
            "output": "91-8734878374",
        },
        {
            "input": "848734878374",
            "output": "62-848734878374",
        },
        {
            "input": "848734878374",
            "output": "84-8734878374",
            "has_country_code": True,
        },
        {
            "input": "848734878374",
            "output": "62-848734878374",
            "has_country_code": False,
        },
        {
            "input": "91848734878374",
            "output": "91-848734878374",
            "has_country_code": True,
        }
    ]

Important Notes

  • Supports only upto five digit country codes as of now
  • Mobile number max length supported is 8-15 characters without country code
  • Please add any test cases you want to add to the input output list and create a PR

Releasing Versions Guide

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

canonical-phone-0.0.10.tar.gz (3.1 kB view details)

Uploaded Source

File details

Details for the file canonical-phone-0.0.10.tar.gz.

File metadata

  • Download URL: canonical-phone-0.0.10.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.2

File hashes

Hashes for canonical-phone-0.0.10.tar.gz
Algorithm Hash digest
SHA256 dc180a4d6978628c90059136b20401fef954af9d361cded688fd5ed84a72d653
MD5 799e99c650b0984168bcf65e35d9fe95
BLAKE2b-256 096e01a267361fd75b6fa35d472e760972dc8241d06c6b86b7f7b145da6306ff

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page