How do I make a code that validate if numbers are used?


Hi! Idk if this is too messy or not, but ill give it a try! I’m creating a password validator, and you need to use atleast 1 number, but how do I make it so that the program check for numbers? I want to do it in the last paragraph, under “function haveNumber(input) {”

Would appreciate the help! Sorry if this is really messy lol.


Upon reaching the unit on functions then you may know already about data structures, control flow and iterators.

Say we have a string,

str = "1m*'!nEq6";

str.split('').filter(x => !isNaN(x)).map(x => +x)
// <- [1, 6]

If all we want is a boolean, then the string array is enough.

const hasNumber = str => str.split('').filter(x => !isNaN(x)).length > 0;

// <- true