JS _ how do to check if an input includes numbers [0-9] ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

JS _ how do to check if an input includes numbers [0-9] ?

I used || to check if it includes 0 - 9. if (input.includes("1") || Input.includes("2") || Input.ncludes("3") || Input.includes("4") || .....) {x = true} ❓ Instead of listing them all like that, is there easier way to check if it includes 0-9 (number)?

25th Jul 2019, 10:11 PM
Ginfio
Ginfio - avatar
5 Answers
+ 1
Ace i dont know what Regex is. u know the actual answer?
25th Jul 2019, 10:42 PM
Ginfio
Ginfio - avatar
0
if( number >= 0 && number <= 9) {...} I don't know where is the peoblem, why would you use regex? Why to complicate when you can do it on the right way
26th Jul 2019, 12:14 AM
Dejan Francuz🥇
Dejan Francuz🥇 - avatar
0
Dejan Francuz🥇 into a string (input), if the input includes or has "0", "1", ... "9", {do somethin}
26th Jul 2019, 12:16 AM
Ginfio
Ginfio - avatar
0
Yes you can: if(isNaN(variable) >= '0' && isNaN(variable) <= '9'){...}
26th Jul 2019, 12:33 AM
Dejan Francuz🥇
Dejan Francuz🥇 - avatar