[whatwg] Maxlength attribute on input[type=number]

Steve Hoeksema steve at kotiri.com
Thu Jun 27 15:18:05 PDT 2013


In my specific case, a numeric code with a maximum length.

Say it's 4 digits, and I'm using Chrome. I can put max=9999, but the browser still allows me to type 12345. It won't allow me to submit the form, and it highlights it as an error, but I can still enter it. Using a maxlength means I can't even enter 12345, and it's obvious that it will only accept 4 digits.

Using input[type=text] is not desirable because (e.g.) it pops up a alphabetical keyboard on iOS instead of a numeric keyboard.

I can of course restrict the length on input[type=number] with javascript, but if the browser supported it natively that would be far better.


On Friday, 28 June 2013 at 10:09 AM, Scott González wrote:

> Why would you want to set maxlength as opposed to setting max?
>  
>  
> On Thu, Jun 27, 2013 at 5:42 PM, Steve Hoeksema <steve at kotiri.com (mailto:steve at kotiri.com)> wrote:
> > Hi,
> >  
> > The current whatwg standard [1] states that maxlength is not a valid attribute for input[type=number].
> >  
> > I built a form and tested it in Firefox, which honours the maxlength attribute, and then found that Chrome did not.
> >  
> > I thought this was a bug, so I reported it to Chromium [2], who determined it was not a bug and referred me to whatwg.
> >  
> > I'm wondering if there is a rationale for not supporting maxlength on a number field, and if not, how I can go about having the standard changed?
> >  
> >  
> > Cheers,
> >  
> > Steve
> >  
> > [1] http://www.whatwg.org/specs/web-apps/current-work/multipage/the-input-element.html#input-type-attr-summary
> > [2] https://code.google.com/p/chromium/issues/detail?id=253798
>  




More information about the whatwg mailing list