Created
November 23, 2016 22:20
-
-
Save Reelix/e93ff93bb1927a09a198a743cd89327c 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
<script> | |
// This function will allow 0123456789, left, right, and backspace on a textbox | |
// Use onkeypress="return isNumericKeyPress(event.keyCode);" to trigger | |
function isNumericKeyPress(keyCode) | |
{ | |
return (keyCode >= 48 && keyCode <= 57 || keyCode === 8); | |
} | |
// This function will clear non-numeric values on a textbox when pasted | |
// Use onpaste="isNumericPaste(this);" to trigger | |
function isNumericPaste(tb) | |
{ | |
setTimeout(function() { void(tb.value = tb.value.replace(/\D/g, '')); }, 1); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment