views:

625

answers:

5

How can i detect caps lock key on/off using jquery.... I have a password textbox and i allow only small letters so i dont want caps lock key to be on....

Is it possible to detect the state of Caps Lock Key using jquery?

A: 

You can do so with javascript, check out this question.

Owen B
A: 

What I do is put up a warning when

  1. the username or password is incorrect and
  2. the username or password provided was all upper-case.

It's a pretty bad idea to only allow smaller letters. You're cutting down the number of possible passwords by a tremendous amount by doing that.

Pointy
+3  A: 

Check this Detection of caps lock using jquery

Adeel
@adeel that worked...
Pandiya Chendur
+1  A: 

How to detect Caps Lock with Javascript.

function capLock(e){
 kc = e.keyCode?e.keyCode:e.which;
 sk = e.shiftKey?e.shiftKey:((kc == 16)?true:false);
 if(((kc >= 65 && kc <= 90) && !sk)||((kc >= 97 && kc <= 122) && sk))
  document.getElementById('divMayus').style.visibility = 'visible';
 else
  document.getElementById('divMayus').style.visibility = 'hidden';
}

then for your password form:

<SPAN><input type="password" name="txtPassword" onkeypress="capLock(event)" />
<SPAN><div id="divMayus" style="visibility:hidden">Caps Lock is on.</div> 
twodayslate
@twodayslate +1 valuable answer too... But i was looking for jquery
Pandiya Chendur
A: 

After the user has created their password, when they’re entering it during login, you could just convert it to lowercase on the server before checking whether it’s correct.

Saves effort for the user that way.

Paul D. Waite