Hello? Yes, This Is Dog

Difficulty:
Medium

Tags:
strings, regular expressions

Instructions:
Write a method to validate some strings that could potentially represent phone numbers. See if you can do it with a regular expression.

Code:
def phone_number?(num)
  ___
end

assert_equal phone_number?("5555555555"), true
assert_equal phone_number?("555555555"), false # missing a digit
assert_equal phone_number?("555-5555"), true
assert_equal phone_number?("(555) 555-5555"), true
assert_equal phone_number?("(555) 555-555"), false
assert_equal phone_number?("555-555-5555"), true
assert_equal phone_number?("555a-555-5555"), false # extraneous digit
assert_equal phone_number?("555*555-5555"), false # extraneous digit
assert_equal phone_number?("55a-555-5555"), false # extraneous digit

Your Solution

Ruby 1.9.3

Back to Problems