Skip to content

Instantly share code, notes, and snippets.

@TMcManus
Created January 3, 2013 18:24
Show Gist options
  • Save TMcManus/4445625 to your computer and use it in GitHub Desktop.
Save TMcManus/4445625 to your computer and use it in GitHub Desktop.
Use the python port of libphonenumber to check that a phone number is of the correct length.

Installing

pip install phonenumbers

Using

$ python length_check.py +17075559876 Prints 'True'

$ python length_check.py +170755598764533 Prints 'False'

import argparse
import phonenumbers as p
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('phonenumber', type=str, action="store",
help='The phone number you want to check.')
args = parser.parse_args()
number_object = p.parse(args.phonenumber)
if p.is_valid_number(number_object) is False:
print "False"
else:
print "True"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment