I want to put an input in html and I want to limit only 2 numbers.
<input type="text" name="Dia" maxlength="2" size="2" >
I tried this one but letters still appear.
input to numbers just change type from text to number :
<form action="#"> <input type="number" name="Dia" min="1" max="31"> <input type="submit"> </form>
Even if you want to limit from 1 to 31 (assuming it is the number of days in the month) you can do this with
Note: This type
number does not work in IE9 or earlier versions.
<form action="#"> <input type="text" maxlength="2" onkeypress='return event.charCode >= 48 && event.charCode <= 57'></input> <input type="submit"> </form>
You can use the event
<input type="text" maxlength="2" onkeypress="if (!isNaN(String.fromCharCode(window.event.keyCode))) return true; else return false;">
Every time a key is pressed within%%, the event will be activated, and it will check whether the key presses a number or not, if it is a letter it returns% with%, if it is a number it will return% with% and it will appear no
See how you got on Fiddle.