Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Challenge: Validate Phone Numbers | Introduction to Regular Expressions
Python Regular Expressions

bookChallenge: 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:

  • 1234567890
  • 123-45-6789
  • abc-def-ghij
Aufgabe

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.

Lösung

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 5
single

single

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

Suggested prompts:

Can you show me how to use this function with some example inputs?

What if the phone number contains spaces or parentheses—will it still be valid?

Can you explain how the regular expression works in this case?

close

Awesome!

Completion rate improved to 6.67

bookChallenge: Validate Phone Numbers

Swipe um das Menü anzuzeigen

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:

  • 1234567890
  • 123-45-6789
  • abc-def-ghij
Aufgabe

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.

Lösung

Switch to desktopWechseln Sie zum Desktop, um in der realen Welt zu übenFahren Sie dort fort, wo Sie sind, indem Sie eine der folgenden Optionen verwenden
War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 5
single

single

some-alt