'Allow only numbers to be typed in a textbox [duplicate]
How to allow only numbers to be written in this textbox ?
<input type="text" class="textfield" value="" id="extra7" name="extra7">
Solution 1:[1]
With HTML5 you can do
<input type="number">
You can also use a regex pattern to limit the input text.
<input type="text" pattern="^[0-9]*$" />
Solution 2:[2]
You also can use some HTML5 attributes, some browsers might already take advantage of them (type="number" min="0").
Whatever you do, remember to re-check your inputs on the server side: you can never assume the client-side validation has been performed.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | HÃ¥ken Lid |
| Solution 2 | Arnout Engelen |
