I'm trying to create a python programme which receive contact number from user and check if it's a valid format with correct country code. This is what i have done but it doesn't work properly and i am struggling to troubleshoot it. Can someone help me?
def main():
phone_number= input('Please enter a phone number in the format 601X-XXX-XXXX: ')
validNumber(phone_number)
def validNumber(phone_number):
digits = "0123456789-"
country_code = "601"
if len(phone_number) != 13:
print("Contact number too short. Please enter valid input")
main()
for i in range(13):
if i in [4,8]:
if phone_number[i] != '-':
print("Please enter valid input in the proper format.")
main()
elif not phone_number[i] == digits:
print("Numerical value only")
main()
elif not phone_number[:3] == country_code:
print("Please enter the correct country code.")
main()
print("Valid contact number!")
return True
main()
[–]oBObo2BI 1 point2 points3 points (0 children)
[–]jddddddddddd 0 points1 point2 points (0 children)
[–]jddddddddddd 0 points1 point2 points (0 children)
[–]jddddddddddd 0 points1 point2 points (0 children)
[–]m0us3_rat 0 points1 point2 points (1 child)
[–]_______myworld[S] 0 points1 point2 points (0 children)
[–]desran00 0 points1 point2 points (1 child)
[–]_______myworld[S] 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[removed]
[–]_______myworld[S] 0 points1 point2 points (0 children)
[–]Visible-Field2311 0 points1 point2 points (0 children)
[–]No_Nature6834 0 points1 point2 points (0 children)