JSFiddle - React, Tailwind, and code Playground
by David Thomas
HTML
<input type="text" maxlength="10" id="myInput">
JavaScript
var input = document.getElementById("myInput");
input.onkeypress = function(e) {
switch (e.keyCode){
case 45:
return this.value.length == 0 ? true : false;
break;
case 48:
case 49:
case 50:
case 51:
case 52:
case 53:
case 54:
case 55:
case 56:
case 57:
return true;
break;
default:
return false;
break;
}
};