Regex validate PIN code

JavaScript

function validatePIN (pin) {
  const pinRegex = new RegExp("^\\d{4}(?:\\d{2})?$");
  return pinRegex.test(pin);
}

Tags

  1. javascript (Private)
  2. 7-kyu (Private)
  3. codewars (Private)
  4. answer (Private)