Added Find Phone Numbers in a string

This commit is contained in:
eazuniga 2019-10-03 08:49:30 +08:00
parent a140a0453e
commit 692ea1fbbb
2 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,24 @@
def check_phone_number(string):
if len(string) != 12:
return False
for i in range(0, 3):
if not string[i].isdecimal():
return False
if string[3] != '-':
return False
for i in range(4, 7):
if not string[i].isdecimal():
return False
if string[7] != '-':
return False
for i in range(8, 12):
if not string[i].isdecimal():
return False
return True
string = input("Enter a Sentence: ")
for i in range(len(string)):
split = string[i:i+12]
if check_phone_number(split):
print('Phone number has been found! : ' + split)

View File

@ -0,0 +1,10 @@
# Find Phone Number in a string
A python script that will extract phone numbers in a string
## Requirements
Python 3.7.3
## Usage
$ python Find-PhoneNumber-in-String.py
Enter a Sentence: Call me in this number 403-867-2229