1

I'm getting confused between xhtml and html5, even after comparing between the two from what's mentioned on w3schools.com.

1

4 Answers 4

5

Is input type=“number” only valid starting from html5?

Yes. http://www.w3.org/TR/html5-diff/#new-elements

6
  • That means there's no way of restricting the user from inputting non-numbers other than doing the checking afterwards?
    – stanigator
    Commented Apr 25, 2012 at 3:15
  • You can do it with custom JavaScript or, even better, an HTML5 shim.
    – Matt Ball
    Commented Apr 25, 2012 at 3:17
  • In order to declare my document to be html5, is it more than just declaring the right doctype?
    – stanigator
    Commented Apr 25, 2012 at 3:17
  • Nope. The doctype defines ...the document type
    – Matt Ball
    Commented Apr 25, 2012 at 3:18
  • 1
    I 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
    – govinda
    Commented Apr 25, 2012 at 3:24
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.

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

0
0

Yes, the number input type is new in HTML5.

http://diveintohtml5.info/forms.html

Not the answer you're looking for? Browse other questions tagged or ask your own question.