diff options
Diffstat (limited to 'misc/isPhoneNumber.py')
-rw-r--r-- | misc/isPhoneNumber.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/misc/isPhoneNumber.py b/misc/isPhoneNumber.py new file mode 100644 index 0000000..6048841 --- /dev/null +++ b/misc/isPhoneNumber.py @@ -0,0 +1,28 @@ +#! /usr/bin/env python3 +# RegEx Chap. 7 + + +def isPhoneNumber(text): + if len(text) != 12: + return False + for i in range(0, 3): + if not text[i].isdecimal(): + return False + if text[3] != '-': + return False + for i in range(4, 7): + if not text[i].isdecimal(): + return False + if text[7] != '-': + return False + for i in range(8, 12): + if not text[i].isdecimal(): + return False + return True + +message = 'Call me at 415-555-1011 tomorrow. 415-555-9999 is my office.' +for i in range(len(message)): + chunk = message[i:i+12] + if isPhoneNumber(chunk): + print('Phone number found: ' + chunk) +print('Done') |