To limit an HTML input box to accept numeric input, use the <input type="number">. With this, you will get a numeric input field.
After limiting the input box to number, if a user enters text and press submit button, then the following can be seen “Please enter a number.”
Example
You can try to run the following code to limit an HTML input box so that it only accepts numeric input −
<!DOCTYPE html> <html> <head> <title>HTML input number</title> </head> <body> <form action = "" method = "get"> Enter any number between 1 to 20: <input type="number" name="num" min="1" max="20"><br> <input type="submit" value="Submit"> </form> </body> </html>