Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think what's missing in the answers above is the need to specify a different value for the <code>step</code> attribute, which has a default value of <code>1</code>. If you want the input's validation algorithm to allow floating-point values, specify a step accordingly.</p> <p>For example, I wanted dollar amounts, so I specified a step like this:</p> <pre><code> &lt;input type="number" name="price" pattern="[0-9]+([\.,][0-9]+)?" step="0.01" title="This should be a number with up to 2 decimal places."&gt; </code></pre> <p>There's nothing wrong with using jQuery to retrieve the value, but you will find it useful to use the DOM API directly to get the elements's <code>validity.valid</code> property.</p> <p>I had a similar issue with the decimal point, but the reason I realized there was an issue was because of the styling that Twitter Bootstrap adds to a number input with an invalid value.</p> <p>Here's a fiddle demonstrating that the adding of the <code>step</code> attribute makes it work, and also testing whether the current value is valid: </p> <ul> <li><strong><a href="http://jsfiddle.net/natchiketa/xrujZ/16/">jsFiddle</a></strong></li> </ul> <p><strong>TL;DR:</strong> <em>Set the a <code>step</code> attribute to a floating-point value, because it defaults to <code>1</code>.</em></p> <p><em><strong>NOTE</strong>: The comma doesn't validate for me, but I suspect that if I set my OS language/region settings to somewhere that uses a comma as the decimal separator, it would work. *note in note*: that was not the case for OS language/keyboard settings *German* in Ubuntu/Gnome 14.04.</em></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload