Question: You're working on a project where you need to validate phone numbers using regular expressions in Python. Write Python code that accomplishes the following: a
You're working on a project where you need to validate phone numbers using regular expressions in Python. Write Python code that accomplishes the following:
a Import the re module for regular expressions.
b Ask the user to enter a phone number.
c Use regular expressions to check if the entered phone number is valid according to the following requirements:
A valid phone number should consist of digits.
It may optionally include hyphens or spaces as separators, but these separators should not appear consecutively.
The phone number should start with one of the following: or
d Print "Valid phone number" if the entered phone number is valid; otherwise, print "Invalid phone number."
Example Output:
Enter a phone number:
Valid phone number
Enter a phone number:
Valid phone number
Enter a phone number:
Invalid phone number
Enter a phone number:
Valid phone number
Python
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
