Input type Number validates if decimal has three digits
See original GitHub issueDescription
It seems that if you have a input[type="number"]
and have the class validate
it will always return the success message if the number has three decimal places (number types shouldn’t have any decimal places).
How to replicate this issue
With the input:
<input type="number" name="amount" id="amount" class="validate">
<label for="amount" data-error="Invalid number (eg. 1200)">Amount</label>
Then the following examples:
Value | Status |
---|---|
0.1 | Fails |
123 | Passes |
123.123 | Passes |
1.123 | Passes |
123.12 | Fails |
1.1234 | Fails |
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
Allow 2 decimal places in <input type="number">
And please specify maximum number of decimal places allowed in the input in data-decimal attribute. it can have values from 0 to any...
Read more ><input type="number"> - HTML: HyperText Markup Language
A number input is considered valid when empty and when a single number is entered, but is otherwise invalid. If the required attribute...
Read more >HTML5 input type=number and decimals/floats in Chrome
So what happens in Chrome with the following HTML when we try to enter a decimal (floating point) number and submit the form?...
Read more >How to restrict input box to allow only numbers and decimal ...
The task is to validate the input when the user is typing something in the input box. Here we are allowing only decimal...
Read more >decimal — Decimal fixed point and floating point arithmetic ...
The module design is centered around three concepts: the decimal number, ... of a new Decimal is determined solely by the number of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Try adding
step="any"
to your input, as described here. I’m thinking that the input is expecting an integer. By addingstep="any"
, both integers and floats will be valid.I found the issue. It has to do with locale and number formatting based on language. So for you guys (assuming you have an English locale) I’m guessing it would occur if you entered
123 456
. But I have yet to test whether these characters are sent upon form submit. Thanks for your help with this issue.