# How to restrict the type of input given to the function Input[]?

The function Input[] when evaluated displays a dialog box where one can enter any character. My question is how do I restrict the input only to a certain type such as numbers or string? I know there is InputString that takes in only strings.

This is what I have tried:

x = Input["Enter a number"];
While[Head[x] == Symbol, x = Input["Enter a number"]]


I believe there is a better solution than this. Can anyone help?

Edit

I am aware of the InputField function. However, I am trying to implement something with the Wolfram Engine and that does not have a front end and I will be using it from the command prompt. Hence, I need to know a way to restrict the input type for the function Input.

• Then just check the result, if it's not what you want, prompt again. Oct 31 '19 at 10:28
• For the WE I'd go with your approach and upgrade it a little: While[Not@MatchQ[x, _String | _?NumericQ], x = Input["Enter a number or a string"]]
– Kuba
Oct 31 '19 at 10:30