I'm getting confused between xhtml and html5, even after comparing between the two from what's mentioned on w3schools.com.
Asked
Active
Viewed 2,441 times
1
-
3http://w3fools.com please read. Its an eye-opener – Thomas Jones Apr 25 '12 at 03:18
4 Answers
5
Is input type=“number” only valid starting from html5?

Matt Ball
- 354,903
- 100
- 647
- 710
-
That means there's no way of restricting the user from inputting non-numbers other than doing the checking afterwards? – stanigator Apr 25 '12 at 03:15
-
You [can do it with custom JavaScript](http://stackoverflow.com/questions/2903806/allowing-just-numeric-text-on-input-text-field) or, even better, [an HTML5 shim](https://gist.github.com/941550). – Matt Ball Apr 25 '12 at 03:17
-
In order to declare my document to be html5, is it more than just declaring the right doctype? – stanigator Apr 25 '12 at 03: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: http://validator.w3.org/ – govinda Apr 25 '12 at 03:24
-
@govinda re: enforcing validation on the server side, that should go without saying. That said, thanks for putting it out there just in case. – Matt Ball Apr 25 '12 at 03:26
2
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.

timdream
- 5,914
- 5
- 21
- 24
1
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

govinda
- 1,683
- 5
- 20
- 34