+ 2

controling what the user inputs in prompt

hello everybody, does any one of you knows how to prevent the user from writing a string in the prompt?

7th Jun 2018, 6:53 PM
Youssef Hammad
Youssef Hammad - avatar
4 Respuestas
+ 4
#1:you have to clearly state in the prompt,that the user has to input something that isnt a string like a number. #2:convert your prompt() from string to your required datatype like parseInt(prompt()); or you could just <input type="number"/> This forces a numeric keyboard on the user
7th Jun 2018, 7:40 PM
᠌᠌Code X
᠌᠌Code X - avatar
+ 1
You mean, something else than numbers? Cause the user always inputs a string.
7th Jun 2018, 7:16 PM
Jonas Schröter
Jonas Schröter - avatar
+ 1
no, I mean he have to put numbers only
7th Jun 2018, 7:32 PM
Youssef Hammad
Youssef Hammad - avatar
+ 1
no strings
7th Jun 2018, 7:32 PM
Youssef Hammad
Youssef Hammad - avatar