Created
March 24, 2019 11:32
-
-
Save inomdzhon/1cb8dd844caa9b15ca5c28f2582a1794 to your computer and use it in GitHub Desktop.
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
// 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