Simple PIN validation

前端 未结 0 872
醉话见心
醉话见心 2021-01-13 08:14

Task: 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,

回答
  •  说谎
    说谎 (楼主)
    2021-01-13 08:31

    function validatePIN (pin) {
      return typeof pin === 'string' && // verify that the pin is a string
        Number.isInteger(+pin) && // make sure that the string is an integer when converted into a number
        [4, 6].includes(pin.toString().length) // only accepts 4 and 6 character pins
    }
    

    0 讨论(0)
提交回复
热议问题