JSFiddle - React, Tailwind, and code Playground

by manoj

HTML

<input class="two-digits" type="text" onkeypress="return isNumber(event)" style="width: 100px;"  />

JavaScript

function isNumber(evt) {
    var foo = 0;
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode != 45 && (charCode != 46) &&
            (charCode < 48 || charCode > 57)) {
        return false;
    }
  // alert(event.target.value)
        if (event.target.value.indexOf('.') > -1) {
        foo = 1;
            //http://www.asquare.net/javascript/tests/KeyCode.html
        if (charCode == 46)
             return false;
     }
    return true;
}