Say we have a number guessing game, and we need the user to guess a number from 1 to 100.
Here's how we would do it: Note that the try block is a bit different.
The hint is displayed in the input field before the user enters a value.
If the condition isn’t met, an error message is displayed to the user.
Numeric field validation is similar to text field validation, but the conditions compare the value of the number entered to some other value.
Figure 5: Numeric conditions constrain user-entered numeric data. Figure 6: Make sure user-entered numeric data is within reasonable bounds. Note that numeric fields are text fields validated to allow only numeric data entry.
That's because the negative sign (-) isn't a digit.