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"/>
You can use the min and max attributes.
The following code do the same:
Here is my solution with jQuery... You have to add maxlength to your input type=number
And handle copy and paste:
I hope it helps somebody.
In my experience most issues where people are asking why
maxlength
is ignored is because the user is allowed to input more than the "allowed" number of characters.As other comments have stated,
type="number"
inputs do not have amaxlength
attribute and, instead, have amin
andmax
attribute.To have the field limit the number of characters that can be inserted while allowing the user to be aware of this before the form is submitted (browser should identify value > max otherwise), you will have to (for now, at least) add a listener to the field.
Here is a solution I've used in the past: http://codepen.io/wuori/pen/LNyYBM
Max length will not work with
<input type="number"
the best way i know is to useoninput
event to limit the maxlength. Please see the below code.maxlenght - input type text
using jQuery:
maxlenght - input type number
JS
HTML
I once got into the same problem and found this solution with respect to my needs. It may help Some one.
Happy Coding :)