blog-banner

To Check Caps Lock is On/Off Status in JQuery

  • Caps Lock
  • Jquery

Jquery Caps Lock Check

 
I'm sure that this script will help you in some of your projects that need a username and password.
Sometimes when we want access to a secure page that asks for a username and password and we submit the information but we didn't know that the password was submitted in the upper case, we get an error.
 

Solution:

jQuery('#username').keypress(function(e) {
  var s = String.fromCharCode( e.which );
  if ( s.toUpperCase() === s && s.toLowerCase() !== s && !e.shiftKey ) {
    jQuery('#capslockdiv').show();
  }
  else {
    jQuery('#capslockdiv').hide();
  }
});
jQuery('#password').keypress(function(e) {
  var s = String.fromCharCode( e.which );
  if ( s.toUpperCase() === s && s.toLowerCase() !== s && !e.shiftKey ) {
    jQuery('#capslockdiv').show();
  }
  else { 
    jQuery('#capslockdiv').hide();
  }
});

Sample HTML code

 

  
  
"capslockdiv" style="display: none;">