Validate Phone Numbers Using ReGex
Beginner Mode

Start your terminal to use beginner mode.

Scenario

A text file contains a list of phone numbers in various formats. You need to validate each phone number against specific format requirements and mark them accordingly.

Task

Write a Python script at /home/interview/validate_phones.py that reads /home/interview/phone_numbers.txt, validates each phone number using regex to match the formats (XXX) XXX-XXXX or XXX-XXX-XXXX, and writes the results to /home/interview/validation_results.txt with each number marked as VALID or INVALID.

Example

Expected output format in /home/interview/validation_results.txt:

(555) 123-4567 - VALID
555-123-4567 - VALID
555.123.4567 - INVALID
5551234567 - INVALID

Terminal requires a larger screen

Open this page on a desktop or tablet (≥ 768px) to launch the terminal and practice hands-on.

Linux Terminal Environment

Write and execute your solution in the terminal below.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →