Skip to content
Advertisement

How to prevent user from entering negative number in react?

I want to restrict users from entering negative values. I am using min = “0”. With this i can restrict users from decrementing to 0, i.e, users can only decrement value till 0. But they are able to type “-“. How to prevent in react js.

https://codesandbox.io/s/react-input-example-forked-xnvxm?file=/src/index.js

JavaScript

Advertisement

Answer

Handling Empty Input & Negative Numbers

JavaScript
Advertisement