Awesome-Python-Scripts/Find-PhoneNumber-in-String/Find-PhoneNumber-in-String.py
2019-10-03 08:53:19 +08:00

24 lines
644 B
Python

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)