Input only numbers (block characters)

[Total: 0    Average: 0/5]

This form only accepts digits.

Body Code:

<script language="javascript"> 
var isIE = document.all?true:false;
var isNS = document.layers?true:false;
function onlyDigits(e) {
  var _ret = true;
  if (isIE) {
    if (window.event.keyCode < 46 || window.event.keyCode > 57) {
      window.event.keyCode = 0;
      _ret = false;
    }
  }
  if (isNS) {
    if (e.which < 46 || e.which > 57) {
      e.which = 0;
      _ret = false;
    }
  }
  return (_ret); 
}
</script> 
<form name=exf1>
<input type=text name="tinput"> 
</form>
<script>
if (isNS) document.captureEvents(Event.KEYPRESS);
document.onkeypress=onlyDigits;
</script> 

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *