Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def isPhoneNumber (text): #647-873-0550
- if len (text) != 12:
- return False #not phone number-sized
- for i in range (0,3):
- if not text [i].isdecimal ():
- return False #no area code
- if text [3] != '-':
- return False #missing dash
- for i in range (4, 7):
- if not text [i].isdecimal():
- return false #no first 3 digits
- if text[7] != '-':
- return False #missing second dash
- for i in range (8, 12):
- if not text[i].isdecimal ():
- return False #missing last 4 digits
- return True
- print (isPhoneNumber ('415-555-1234'))
- message = "Call me tomorrow at 415-555-1234 tomorrow, or at 647-873-4576 to reach my work number.'
- foundnumber= False
- for i in range (len(message)):
- chunk = message [i:i+12]
- if isPhoneNumber (chunk):
- print ('Pjone number found : ' + chunk)
- foundnumber = True
- if not foundnumber:
- print ('Could not find any phone numbers.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement