Skip to content

Latest commit

 

History

History
31 lines (23 loc) · 781 Bytes

valid-phone-number.md

File metadata and controls

31 lines (23 loc) · 781 Bytes

Valid Phone Number 6 Kyu

LINK TO THE KATA - REGULAR EXPRESSIONS ALGORITHMS

Description

Write a function that accepts a string, and returns true if it is in the form of a phone number. Assume that any integer from 0-9 in any of the spots will produce a valid phone number.

Only worry about the following format: (123) 456-7890 (don't forget the space after the close parentheses)

Examples:

"(123) 456-7890"  => true
"(1111)555 2345"  => false
"(098) 123 4567"  => false

Solution

const validPhoneNumber = phoneNumber => {
  return /^\(\d{3}\) \d{3}-\d{4}$/.test(phoneNumber)
}