Last active
February 15, 2018 14:16
-
-
Save app06/e836f4fce311ecbf943b040a7811316b 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
//only integer input | |
function onlyInt(e) { | |
if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 || | |
(e.keyCode === 65 && (e.ctrlKey === true || e.metaKey === true)) || | |
(e.keyCode >= 35 && e.keyCode <= 40)) { | |
return; | |
} | |
if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) { | |
e.preventDefault(); | |
} | |
} | |
if ( $('.only-int').length ) { | |
$('.only-int').on('keydown', function(e) { | |
return onlyInt(e); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment