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.

Number input breaks when letter "e" is entered

See original GitHub issue

Do you want to request a feature or report a bug? bug

What is the current behavior? input[type=number] only allows entering numbers and letter “e” in the input. Native “input” input event is called for both numbers and the letter “e”. With React the onChange event is only called for numbers. There’s no way to catch “e” with onChange.

The “e” is even being filled when the input is controlled. The only way I can think of to work around this bug right now is to use onKeyDown and preventDefault when “e” or “E” is pressed.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn’t have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below: https://codesandbox.io/s/ov3ql3ljwz

What is the expected behavior? It should pass anything that is being filled into the input to the onChange handler and should not break controlled component.

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React? React: 16.4.2 Chrome: 68.0.3440.106 Windows 10

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:10
  • Comments:15 (12 by maintainers)

github_iconTop GitHub Comments

18reactions
mgolcommented, Jan 10, 2020

This is still an issue.

3reactions
Yurickhcommented, Aug 28, 2018

From what I could experiment with your codesandbox, the onChange is still being called (with an empty value) for when you type “e”. Additionally, if you type anything after the “e”, it will send the value properly.

I believe this is happening because a string ending with “e” is not a valid number (e.g. 12e), but a string with “e” followed by an integer is (e.g. 12e2). Remember that 12e2 is a valid number, as Ende93 pointed out.

Notice the onChange will be called with an empty value for any other non-number string (e.g. foo), so it looks quite consistent to me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does the html input with type "number" allow the letter ' ...
HTML input number type allows "e/E" because "e" stands for exponential which is a numeric ... Using angular, You can do this to...
Read more >
Why the number input is the worst input
When the number input contains an invalid value and you retrieve the value, you get a blank string. · Valid numbers include more...
Read more >
TextBox Type Number Allowing to type letter "e"
The ASP.NET TextBox control generates HTML like <input type="number" />, but it's up to the browser to restrict what characters you can type...
Read more >
C++ Reading a Line of Text
The letter “e” is then output. A more common usage is cin.ignore() with nothing in parentheses. This ignores all input until the next...
Read more >
Program to check if input is an integer or a string
Definition of a string : Any one element should be an invalid digit, i.e any symbol other than '0-9'. Examples: Input ...
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