I am asked to create a function that takes a string to check whether the string is valid or not.
A valid string has the following conditions.
Exactly 4 or 6 characters.
Only numerical characters (0-9).
No whitespace
My solution does not work.
function test(num){
return num.length === 4 || num.length === 6;
}
console.log(test("123445"),true);
console.log(test("801264"),true);
console.log(test("451352"),true);
console.log(test("881234"),true);
console.log(test("as89abc1"),false);
console.log(test(" "),false);
console.log(test(" 4983 "),false);
console.log(test("123 "),false);