function checkNumber(event,objThis) { var eventKey = document.all ? event.keyCode : event.which; if(!(eventKey>=48&&eventKey<=57) && eventKey != 8 ) return false; } <input type="text" size="4" maxlength="4" value="2" name="count" onkeypress="return checkNumber(event,this);">