Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input Number allows a-z characters #9421

Closed
jgmurillo10 opened this issue Feb 26, 2018 · 21 comments
Closed

Input Number allows a-z characters #9421

jgmurillo10 opened this issue Feb 26, 2018 · 21 comments
Labels
❓FAQ issues would be discussed a lot

Comments

@jgmurillo10
Copy link

Version

3.2.2

Environment

MacOS, Google Chrome

Reproduction link

https://codesandbox.io/s/ox7mmz9n7y

Steps to reproduce

type in the InputNumber component

What is expected?

It must not allow the user to type a-z characters.

What is actually happening?

The InputNumber allows the user to type a-z characters


It is required the attribute type="number"

@afc163
Copy link
Member

afc163 commented Feb 27, 2018

The interaction is by designed as <input type="number" />, which is allowed to input non-digits char in safari or firefox.

@afc163 afc163 closed this as completed Feb 27, 2018
@jaisonjjames
Copy link

jaisonjjames commented Apr 2, 2018

@afc163 https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/number
for Input number, we can not enter an alphabet, looking for the same feature on our inputNumber

@luanpotter
Copy link

Clearly the InputNumber should at least have an option to disallow letters, shouldn't it? Is there any workarounds?

@ztplz
Copy link
Contributor

ztplz commented Dec 13, 2018

@luanpotter Please set type to number.

@luanpotter
Copy link

Hi, @ztplz , thanks so much for your feedback, it's working now!

@avalanche1
Copy link

@ztplz This is undocumented feature. It should be:

  1. Documented
  2. Set as default

Pls reopen!

@nossbigg
Copy link
Contributor

nossbigg commented Nov 22, 2019

I also agree with @avalanche1, as most people would expect <InputNumber> to accept only numbers by default (unless this behavior is explicitly overridden).

Seems like there's resistance for this change to be implemented in the underlying library rc-number-input too (see: react-component/input-number#113)

I guess the best way forward is that we just set type="number" when using <InputNumber> (as per #9421 (comment)) and move on 😕🤷🏻‍♂️

@guillermovasta
Copy link

type="number" doesn't work in Safari 14.1.

@ConorTighe
Copy link

ConorTighe commented Apr 20, 2022

In the onChange you can use the following to get around this with or without type="number" on the <Input /> component.

const onChange = (value) => {
    if (isNaN(value)) return;
    ... do stuff
  };

@DouggyC
Copy link

DouggyC commented Nov 21, 2022

hows to trigger

In the onChange you can use the following to get around this with or without type="number" on the <Input /> component.

const onChange = (value) => {
    if (Number.isNaN(value)) return;
    ... do stuff
  };

how to trigger Forrm.Item warning message from onChannge?

@prakashmallow
Copy link

type="number" is not working on the Firefox browser. Please check and fix it. I need to not allow characters to type on InputNumber. How to achieve this?

@yoyo837
Copy link
Contributor

yoyo837 commented Apr 16, 2023

It sounds like <Input /> would be more suitable for your needs.

@prakashmallow
Copy link

prakashmallow commented Apr 16, 2023

@yoyo837 I tried with but the type="number" is not working on Firefox browser.

@yoyo837
Copy link
Contributor

yoyo837 commented Apr 16, 2023

I mean this #9421 (comment)

@prakashmallow
Copy link

@yoyo837 I will try this #9421 (comment)
and update here

@prakashmallow
Copy link

@yoyo837 @ConorTighe #9421 (comment) is not working.

@yoyo837
Copy link
Contributor

yoyo837 commented Apr 17, 2023

@yoyo837 @ConorTighe #9421 (comment) is not working.

What it is you really want? confirm again.

@prakashmallow
Copy link

@yoyo837 InputNumber only allows entering numbers only. Don't allow text and special characters.

@yoyo837
Copy link
Contributor

yoyo837 commented Apr 17, 2023

@yoyo837 InputNumber only allows entering numbers only. Don't allow text and special characters.

Yes, but <Input /> can do that. it allows you to enter any character.

@ConorTighe
Copy link

ConorTighe commented Jun 12, 2023

@yoyo837 @prakashmallow try isNaN

const onChange = (value) => {
    if (isNaN(value)) return;
    console.log(value);
  };

onChange(100);
onChange("aaa");
onChange(200);

@ConorTighe
Copy link

ConorTighe commented Jun 12, 2023

You could also do this which would probably be best:

const onChange = (value) => {
    const userInput = Number(value); // immutable value
    if (Number.isNaN(userInput)) return;
    console.log(userInput);
  };

onChange(100);
onChange("aaa");
onChange("@@@");
onChange("1000");
onChange(200);

Output when testing:

100
1000
200

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❓FAQ issues would be discussed a lot
Projects
None yet
Development

No branches or pull requests