<input type="number" maxlength="5" class="search-form-input" name="techforge_apartmentbundle_searchformtype[radius]" id="techforge_apartmentbundle_searchformtype_radius">
This is my HTML, taken with firebug (on chrome).
I am allowed to write as much as characters as I want in the form field - in Chrome and Safari.
When on Firefox or IE10, the limit is fine.
I haven't found this issue around on the net.
Note: type="number" - not text.
Anyone saw this issue before?
If your input is of type "number", the max length will not work. You can use javascript to try to limit, or you can use a Text Input instead, attached to a number variable, if you do not need the spin buttons.
All browsers support maxlength. However, this attribute can easily be removed/changed using DOM methods or, for example, with Firefox's Web Developer Toolbar.
The maxlength attribute defines the maximum number of characters (as UTF-16 code units) the user can enter into an <input> or <textarea> . This must be an integer value 0 or higher. If no maxlength is specified, or an invalid value is specified, the input or textarea has no maximum length.
Max length will not work with <input type="number"
the best way i know is to use oninput event to limit the maxlength. Please see the below code.
<input name="somename" oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);" type = "number" maxlength = "6" />
Use the max attribute for inputs of type="number"
. It will specify the highest possible number that you may insert
<input type="number" max="999" />
if you add both a max and a min value you can specify the range of allowed values:
<input type="number" min="1" max="999" />
See this example
EDIT
If, for user experience, you would prefer the user not to be able to enter more than a certain number, use Javascript/jQuery, as seen in this example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With