JSFiddle - React, Tailwind, and code Playground

by tonyleeper

HTML

<input id="password" type="password" />

JavaScript

/**
    prevent capslock on password field
*/

(function($) {
    $.fn.noCapsLock = function(message) {
        this.keypress(function (e) {
            var char = String.fromCharCode(e.which);
            if (char.toUpperCase() === char && char.toLowerCase() !== char && !e.shiftKey) {
                window.alert(message);
                e.preventDefault();
            }         
        });
    };
})(jQuery);

$(function () {
    $('#password').noCapsLock('Please turn off caps lock!');
});