Ad

How To Make Input Form Only Numbers

- 1 answer

I'm making input that user could only type number or float number. If I type text it clears out whole input.I want forbid type text without clearing field . Any ideas how to make it?

<input
   type="text"
   id="willBeCreditedAmount"
   maxLength={9}
   placeholder="Enter amount"
   pattern="[0-9]*"
   onChange={(e) => this.props.updateWillBeCreditedAmount(e.target.value, currentComProfile)
   }
   value={willBeCreditedAmount}
/>
Ad

Answer

You can use this code

<form>
  <input type="number" id="myNumber" value="1">
</form>

Ad
source: stackoverflow.com
Ad