This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

http://programmingpraxis.com/2011/12/13/validating-telephone

By: a guest on Dec 13th, 2011  |  syntax: Python  |  size: 0.36 KB  |  views: 241  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. from re import compile
  2.  
  3. VALID_PHONE_PATTERNS = [
  4.     "\d{10}",
  5.     "\d{3}\-\d{3}\-\d{4}",
  6.     "\d{3}\.\d{3}\.\d{4}",
  7.     "\(\d{3}\)\s?\d{3}\-\d{4}",
  8.     "\d{3}\-\d{4}"]
  9.    
  10. def validate_phone_number(phn):
  11.    
  12.     for pattern in VALID_PHONE_PATTERNS:
  13.         myre = compile(pattern)
  14.         if myre.match(phn):
  15.             return True
  16.     return False
  17.  
clone this paste RAW Paste Data