Skip to content

Latest commit

 

History

History
21 lines (17 loc) · 546 Bytes

validate_code_with_simple_regex.md

File metadata and controls

21 lines (17 loc) · 546 Bytes

Description

Basic regex tasks. Write a function that takes in a numeric code of any length. The function should check if the code begins with 1, 2, or 3 and return true if so. Return false otherwise.

You can assume the input will always be a number.

My Solution

def validate_code(code)
  /^[123]/.match?(code.to_s)
end

Better/Alternative solution from Codewars

def validate_code(code)
  /\A[123]/ === code.to_s
end