It seems the minlength
attribute for an <input>
field doesn't work.
Is there any other attribute in HTML5 with the help of which I can set the minimal length of a value for fields?
It seems the minlength
attribute for an <input>
field doesn't work.
Is there any other attribute in HTML5 with the help of which I can set the minimal length of a value for fields?
Here is HTML5-only solution (if you want minlength 5, maxlength 10 character validation)
http://jsfiddle.net/xhqsB/102/
In my case, in which I validate the most at hand and using Firefox (43.0.4),
minlength
andvalidity.tooShort
are not available unfortunately.But since I only need to have minimum lengths stored to proceed, an easy and handy way is to assign this value to another valid attribute of the input tag. In that case then, you can use
min
,max
, andstep
of other properly from non-text type inputs (type="number"), but still inputs.Rather than storing those limits in an array it's easier to find it stored in the same input instead of getting the element id to match the array index.
Yes, there it is. It's like maxlength. W3.org documentation: http://www.w3.org/TR/html5/forms.html#attr-fe-minlength
In case
minlength
doesn't work, use thepattern
attribute as mentioned by @Pumbaa80 for theinput
tag.For textarea: For setting max; use
maxlength
and for min go to this link.You will find here both for max and min.
Not HTML5, but practical anyway: if you happen to use AngularJS, you can use
ng-minlength
for both inputs and textareas. See also this Plunk.I wrote this JavaScript code, [minlength.js]:
If desire to make this behavior,
always show a small prefix on input field or the user can't erase a prefix: