The maxlength
attribute is not working with <input type="number">
. This happens only in Chrome.
<input type="number" class="test_css" maxlength="4" id="flight_number" name="number"/>
The maxlength
attribute is not working with <input type="number">
. This happens only in Chrome.
<input type="number" class="test_css" maxlength="4" id="flight_number" name="number"/>
DEMO - JSFIDDLE
I know there's an answer already, but if you want your input to behave exactly like the
maxlength
attribute or as close as you can, use the following code:Many guys posted
onKeyDown()
event which is not working at all i.e. you can not delete once you reach the limit. So instead ofonKeyDown()
useonKeyPress()
and it works perfectly fine.Below is working code: