Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
JS: detect caps lock
function checkCapslock (e) {
var $el = $(this),
hasLabel = $el.parent().find('.capslock-on-alert').length > 0 ? true : false;
var kc = e.keyCode?e.keyCode:e.which;
var sk = e.shiftKey?e.shiftKey:((kc == 16)?true:false);
var isCaps = ((kc >= 65 && kc <= 90) && !sk)||((kc >= 97 && kc <= 122) && sk);
if(isCaps && !hasLabel) {
$el.after('<label for="password" generated="true" class="error capslock-on-alert">Klawisz CAPS LOCK jest włączony.</label>');
} else if(!isCaps && hasLabel) {
$('.capslock-on-alert').remove();
}
}
$('input[type="password"]').live('keypress', checkCapslock);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.