-
-
Save ekahialoha/987ff167762c3e0169bc4fae160c7f4a to your computer and use it in GitHub Desktop.
Keypress Validation
ALLOW CHARACTERS: a..z A..Z 0..9 - _ . , @ Reference keycode table: http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes
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
$('input').bind('keypress', function(e) {// Kami.2013.12.24.10:57 Allow only letters, numbers, and @ , . - _ | |
var allowedCode = [8, 13, 32, 44, 45, 46, 95]; | |
var charCode = (e.charCode) ? e.charCode : ((e.keyCode) ? e.keyCode : | |
((e.which) ? e.which : 0)); | |
if (charCode > 31 && (charCode < 64 || charCode > 90) && | |
(charCode < 97 || charCode > 122) && | |
(charCode < 48 || charCode > 57) && | |
(allowedCode.indexOf(charCode) == -1)) { | |
e.preventDefault(); | |
$('.alert-box.onerror').html('<h3>ALLOW CHARACTERS: a..z A..Z 0..9 - _ . , @</h3>').fadeIn(); | |
return false; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment