question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Input type Number validates if decimal has three digits

See original GitHub issue

Description

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:closed
  • Created 7 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ghostcommented, Feb 4, 2017

Try adding step="any" to your input, as described here. I’m thinking that the input is expecting an integer. By adding step="any", both integers and floats will be valid.

0reactions
Jujunolcommented, Feb 9, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found