Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

allow only numbers in textbox javascript onkeypress

<input class="text" name="Serial_Num" type="text" id="SrNo" size="2" maxlength="2" onkeypress="return digitKeyOnly(event)" />
 Run code snippet
Comment

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 )
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: Add Click events to multiple classes. 
Javascript :: angular auth guard @medium 
Javascript :: javascript reduce mdn 
Javascript :: CDNs for arquero 
Javascript :: unreachable code detected javascript 
Javascript :: proxy{} map in console 
Javascript :: inject html string to div javascript 
Javascript :: Shopify cart context 
Javascript :: Listen to custom event in Vue.js 
Javascript :: knex js how to group by many items 
Javascript :: save input local storage react 
Javascript :: kayengxiong promise js 
Javascript :: regex mobile 
Javascript :: multi command run in one in terminal npm 
Javascript :: react lifecycle 
Javascript :: index wise print elemnet in javascript 
Javascript :: nodejs split array into chunks 
Javascript :: get 3 random items from array javascript 
Javascript :: access data from dofferent file in js 
Javascript :: how to get specific property name with numbers from object in javascript 
Javascript :: find symmetrical difference of arrays 
Javascript :: how to use handlebars.registerhelper if null 
Javascript :: how to render array buffer binary audio js 
Javascript :: how to add another model into type of model in mongodb schema 
Javascript :: docker containerize node app 
Javascript :: React.js setState on page load not working, how to fix 
Javascript :: how to know the number of eventlisteners in javascript 
Javascript :: Prevent the wiping of an Array after routing Angular.js 
Javascript :: How to query a button with specific text with react native testing library 
Javascript :: How to check the increase/decrease of letter input in pasting clipboard in jQuery 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =