How to make HTML input tag only accept numerical values? in jsx 1

How to make HTML input tag only accept numerical values? in jsx

 {
        if (!/[0-9]/.test(event.key)) {
          event.preventDefault();
        }
      }}
    />

Here is what the above code is Doing:
1. We’re using the onKeyPress event handler to listen for key presses.
2. We’re using a regular expression to test the key that was pressed.
3. If the key that was pressed is not a number, we’re preventing the default behavior.

Similar Posts