I'm getting confused between xhtml and html5, even after comparing between the two from what's mentioned on w3schools.com.
4 Answers
Is input type=“number” only valid starting from html5?
-
That means there's no way of restricting the user from inputting non-numbers other than doing the checking afterwards? Commented Apr 25, 2012 at 3:15
-
-
In order to declare my document to be html5, is it more than just declaring the right doctype? Commented Apr 25, 2012 at 3:17
-
-
1I always got the advice to never trust client-side technologies alone to validate user input. Anything client side can be hacked.. so have server-side code as the final failsafe/fallback (after your HTML(5) inputs and any javascript do their best to validate). Your server-side code should be the ultimate authority about whether or not user input meets the criteria you need it to, for security and proper functioning of your app. ... and you'll want to validate your code.. to be sure your HTML matches what your declared doctype says how it should be written: validator.w3.org– govindaCommented Apr 25, 2012 at 3:24
The beauty of HTML5 is that the spec authors design it to be as backward compatible as possible.
When browser process HTML, it normalizes attributes to properties. number
will fallback to normal text
in a browser that doesn't provide the number
capability.
So yes and no. It's only valid in HTML5, but you can use it on HTML4-3-2-1 browsers.
I believe type="number"
attribute for input is HTML5 only. I also keep reading many trust-worthy experts saying more and more to use this resource over the often less-technically-accurate w3schools.com :
https://developer.mozilla.org/
e.g.
https://developer.mozilla.org/en/HTML/Element/Input
HTH