html input only digits code example
Example 1: html restrict input to numbers
<input type="text" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');" />
Example 2: html input only 4 digits
<input type="text" name="pincode" maxlength="4" id="pin" pattern="^0[1-9]|[1-9]\d$" required/>