如何编写javascript只允许数字和选项卡

问题描述:

.............................................
thankxxxxx

.............................................
thankxxxxx

试试这个:



try this :


.numericalOnly)。keypress(function (e){
if (key === 9 ){ // 按下TAB
返回 false ;}

if String .fromCharCode(e.keyCode).match(/[^0-9]/g)) return false ;
}
});
(".numericOnly").keypress(function (e) { if (key === 9 ) { //TAB was pressed return false;} if (String.fromCharCode(e.keyCode).match(/[^0-9]/g)) return false; } });


<script>function checkInput(ob) {
  var invalidChars = /[^0-9]/gi
  if(invalidChars.test(ob.value)) {
            ob.value = ob.value.replace(invalidChars,"");
      }
}