Regex

Validate Phone Number

mediumregexregexvalidation
0:00

Problem

Return `true` if the input is a valid North American phone number in the format (XXX) XXX-XXXX, XXX-XXX-XXXX, or XXX.XXX.XXXX.

Your solution
Test results
Click Run tests to check your solution against the test cases.

About this challenge

Validate Phone Number is a medium regex coding challenge. It tests your command of regular expressions — pattern-matching that trips up even experienced developers. Write your solution in the editor above, run it against the test cases, and get instant feedback — free, in your browser, no sign-up.

Show a hint & approach (spoiler)

Hint: Try `/^(\(\d{3}\)\s|\d{3}[-.])\d{3}[-.]\d{4}$/`.

Keep practicing

Browse all coding challenges, or build intuition for the underlying concepts with the algorithm visualizers and the developer cheatsheets.