Skip to content

Instantly share code, notes, and snippets.

@inomdzhon
Created March 24, 2019 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inomdzhon/1cb8dd844caa9b15ca5c28f2582a1794 to your computer and use it in GitHub Desktop.
Save inomdzhon/1cb8dd844caa9b15ca5c28f2582a1794 to your computer and use it in GitHub Desktop.
// other way
function isNumber(evt) {
evt = (evt) ? evt : window.event;
var charCode = (evt.which) ? evt.which : evt.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
return false;
}
return true;
}
// my solution
function checkingTypeValue(evt) {
_$targetQuantityItem = this;
var value = _$targetQuantityItem.value;
if ( (/[^0-9]/gi).test(value) || +value === 0 ) {
_$targetQuantityItem.value = '';
}
var MAX_VALUE = _$targetQuantityItem.getAttribute('data-max') || 0;
if (+value > MAX_VALUE) {
_$targetQuantityItem.value = MAX_VALUE;
}
_checkItemAndShowMessage();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment