只能输入数字(2)支持backspace

只能输入数字(2)支持backspace
function checkNumber(e) {    
  var key = window.event ? e.keyCode : e.which;    
  var keychar = String.fromCharCode(key);        
  reg = /\d/;    
  var result = reg.test(keychar);    
 if(!result){              
   return false;    
 }else{               
   return true;    
 }
}

<input type="text" style="width:20px;" class="textfield" name="recPerPageStr" value="<%=recPerPageStr%>" maxlength="2" onkeypress="return checkNumber(event);" />

你可能感兴趣的:(只能输入数字(2)支持backspace)