Skip to content

Latest commit

 

History

History
33 lines (24 loc) · 726 Bytes

regex-validate-pin-code.md

File metadata and controls

33 lines (24 loc) · 726 Bytes

Regex validate PIN code 7 Kyu

LINK TO THE KATA - REGULAR EXPRESSIONS FUNDAMENTALS

Description

ATM machines allow 4 or 6 digit PIN codes and PIN codes cannot contain anything but exactly 4 digits or exactly 6 digits.

If the function is passed a valid PIN string, return true, else return false.

Examples (Input --> Output)

"1234"   -->  true
"12345"  -->  false
"a234"   -->  false

Solution

const validatePIN = pin => {
  if (pin.length === 4 || pin.length === 6) {
    return /^\d+$/.test(pin)
  }

  return false
}