Skip to content

Instantly share code, notes, and snippets.

@adeel-raza
Created April 6, 2017 15:35
Show Gist options
  • Save adeel-raza/e6b5f3167035a9f9488a52c8119b3d45 to your computer and use it in GitHub Desktop.
Save adeel-raza/e6b5f3167035a9f9488a52c8119b3d45 to your computer and use it in GitHub Desktop.
Limit the range of a numeric textbox with Jquery
jQuery("#textbox_id").on("keypress", function(e){
var currentChar = parseInt(String.fromCharCode(e.keyCode), 10);
if(!isNaN(currentChar)){
var nextValue = elem.val() + currentChar; //It's a string concatenation, not an addition
if(parseInt(nextValue, 10) <= 20) return true;
}
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment