Challenge: Validate Phone Numbers
Write a function that checks whether a given string matches the format of a US phone number such as 123-456-7890. The format requires:
- Three digits;
- A dash (
-); - Three more digits;
- Another dash (
-); - Four digits.
Use regular expressions to perform this validation. The function should return True if the input string matches the required pattern, and False otherwise.
Example valid phone number:
123-456-7890
Example invalid phone numbers:
1234567890123-45-6789abc-def-ghij
Swipe to start coding
Write a function named is_valid_phone_number that returns True if the input matches the US phone number format 123-456-7890, and False otherwise. The phone number must have:
- Three digits;
- A dash;
- Three digits;
- A dash;
- Four digits.
Use regular expressions for the validation. If the string matches this pattern exactly, return True; otherwise, return False.
Solution
Thanks for your feedback!
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Can you show me the function implementation?
Can you explain how the regular expression works in this case?
Can you provide more examples of valid and invalid phone numbers?
Awesome!
Completion rate improved to 6.67
Challenge: Validate Phone Numbers
Swipe to show menu
Write a function that checks whether a given string matches the format of a US phone number such as 123-456-7890. The format requires:
- Three digits;
- A dash (
-); - Three more digits;
- Another dash (
-); - Four digits.
Use regular expressions to perform this validation. The function should return True if the input string matches the required pattern, and False otherwise.
Example valid phone number:
123-456-7890
Example invalid phone numbers:
1234567890123-45-6789abc-def-ghij
Swipe to start coding
Write a function named is_valid_phone_number that returns True if the input matches the US phone number format 123-456-7890, and False otherwise. The phone number must have:
- Three digits;
- A dash;
- Three digits;
- A dash;
- Four digits.
Use regular expressions for the validation. If the string matches this pattern exactly, return True; otherwise, return False.
Solution
Thanks for your feedback!
single