Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

allow only numbers in textbox javascript onkeypress

function digitKeyOnly(e) {
  var keyCode = e.keyCode == 0 ? e.charCode : e.keyCode;
  var value = Number(e.target.value + e.key) || 0;

  if ((keyCode >= 37 && keyCode <= 40) || (keyCode == 8 || keyCode == 9 || keyCode == 13) || (keyCode >= 48 && keyCode <= 57)) {
    return isValidNumber(value);
  }
  return false;
}

function isValidNumber (number) {
  return (1 <= number && number <= 10 )
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #numbers #textbox #javascript #onkeypress
ADD COMMENT
Topic
Name
5+8 =