mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2024-11-23 20:11:07 +00:00
Added Find Phone Numbers in a string
This commit is contained in:
parent
a140a0453e
commit
692ea1fbbb
24
Find-PhoneNumber-in-String/Find-PhoneNumber-in-String.py
Normal file
24
Find-PhoneNumber-in-String/Find-PhoneNumber-in-String.py
Normal 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)
|
10
Find-PhoneNumber-in-String/README.md
Normal file
10
Find-PhoneNumber-in-String/README.md
Normal 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
|
Loading…
Reference in New Issue
Block a user