Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

extract area code from phone number python

#this only works for numbers in Toronto or the greater toronto area, but its simple to expand it for more areas.
phone = input("Enter a 10 digit phone number: ")
phone = str.replace(phone, "(", "") #removes brackets
phone = str.replace(phone, ")", "") #removes brackets
phone = str.replace(phone, "-", "") #removes dashes
phone = str.replace(phone, " ", "") #removes spaces
areacode = phone[0:3]
if areacode == "416" or areacode == "647":
    print("This is a Toronto number")
elif areacode == "905" or areacode == "289":
    print("This is a GTA number")
 
PREVIOUS NEXT
Tagged: #extract #area #code #phone #number #python
ADD COMMENT
Topic
Name
4+1 =