Skip to content

Instantly share code, notes, and snippets.

@zmiftah
Created December 14, 2017 09:50
Show Gist options
  • Save zmiftah/c57184eecd74d9c7cfb6d02ec75a868d to your computer and use it in GitHub Desktop.
Save zmiftah/c57184eecd74d9c7cfb6d02ec75a868d to your computer and use it in GitHub Desktop.
let input = $('#txt_number')
function validateNumberKey(e) { //keydown
let newVal = this.value + e.key
return e.keyCode == 36 || // e.key=Home
e.keyCode == 8 || // e.key=Backspace
e.keyCode == 37 || // e.key=ArrowLeft
e.keyCode == 39 || // e.key=ArrowRight
$.isNumeric(newVal)
}
input.on('keydown', validateNumberKey)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment