Created
April 6, 2017 15:35
-
-
Save adeel-raza/e6b5f3167035a9f9488a52c8119b3d45 to your computer and use it in GitHub Desktop.
Limit the range of a numeric textbox with Jquery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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