I want the function to return true if the user has entered 4 or 6 digits. And false in all other cases. Entered letters, more characters, etc.
validatePIN("1234") === true validatePIN("12345") === false validatePIN("a234") === false
Function code:
function validatePIN (pin) { //return true or false if (pin.length == 4) { return true; } else if (pin.length == 6) { return true; } return false; }
How can I correctly organize the verification that there are no characters in the line except numbers from 1 to 9.
Regular expression solution:
^(\d{4}|\d{6})$
Ps if anyone knows show how to do without RegExp
0
not allowed? - Vladimir Gamalyan