Skip to content

Instantly share code, notes, and snippets.

@pythonjunkie
Created September 7, 2012 00:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pythonjunkie/3661745 to your computer and use it in GitHub Desktop.
Save pythonjunkie/3661745 to your computer and use it in GitHub Desktop.
Validate length of a phone number
import re
def check_mdn(mdn, mdn_re = re.compile('^\d{10,15}$')):
''' Check if MDN is acceptable
'''
print " MDN: %s " % mdn
if mdn_re.match(str(mdn)):
print " %s is fine " % mdn
return True
else:
print " %s is not fine" % mdn
return False
mdn = '1234'
mdn1 = '1212121212'
mdn12= '121212121212'
mdn15= '121212121212121'
mdn18= '123456789012345678'
check_mdn(mdn)
check_mdn(mdn1)
check_mdn(mdn12)
check_mdn(mdn15)
check_mdn(mdn18)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment