I'm using the jQuery Tools Validator which implements HTML5 validations through jQuery.
It's been working great so far except for one thing. In the HTML5 specification, the input type "number"
can have both integers and floating-point numbers.
This seems incredibly short-sighted since it will only be a useful validator when your database fields are signed floating-point numbers (for unsigned ints you'll have to fall back to pattern
validation and thus lose extra features like the up and down arrows for browsers that support it).
Is there another input type or perhaps an attribute that would restrict the input to just unsigned integers?
I couldn't find any.
Setting the step to 1 is not the answer since it doesn't restrict the input. You can still type a negative floating-point number into the textbox.
Also, I am aware of pattern validation (I mentioned it in my original post), but that was not part of the question.
I wanted to know if HTML5 allowed restricting an input of type "number" to positive integer values. To this question the answer, it seems, would be "no, it does not".
I didn't want to use pattern validation because this causes some drawbacks when using jQuery Tools validation, but it now seems that the specification doesn't allow for a cleaner way to do this.
number
input (in FF/Chrome/Safari at least) now only accepts integers by default, unless you set an explicit value for thestep
attr that allows decimal values; e.g:step="0.01"
. Documented MDN here. In two minds about this because I think it's a sensible default, but also a breaking change (yes, it has affected some code I wrote). – Echoismstep="1"
. MDN says the behavior is up to the browser. – Acculturize