I'm trying to solve this 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, return true, else return false.
eg:
validatePIN("1234") === true validatePIN("12345") === false validatePIN("a234") === false
And this is my code:
function validatePIN (pin) {
if(pin.length === 4 || pin.length === 6 ) {
if( /[0-9]/.test(pin)) {
return true;
}else {return false;}
}else {
return false;
}
}
It shows that --- Wrong output for 'a234' - Expected: false, instead got: true ---Why? This /[0-9]/ shows only numbers?
Thank you in advance :)