The user enters information in the text box. You need to somehow check whether Caps Lock is on and if so, then disable it. Is it possible to implement this using javascript?

  • why not just enter values ​​always in lower case? - ThisMan
  • @ThisMan Hundreds of users come to the site every day and try to explain to everyone what you need to write in the text field in lower case - aleks_sk
  • @aleks_sk, no, you do not understand, why not programmatically reduce the entered value to lower case? - ThisMan

1 answer 1

You can check whether Caps Lock is on, for example using this library.

If you want the field to enter data only in lower case, that is, the option is much better without using JS, add a style to the input field:

text-transform: lowercase; 

For example:

 <input name="email" type="text" style="text-transform: lowercase;"> 

UPD: If you want the input value to be in lower case, then the simplest option:

 $(document).on('keyup', 'input', function() { if (CapsLock.isOn()){ $(this).val($(this).val().toLowerCase()); } }); 

You can even translate everything to lower case right away, just remove the CapsLock.isOn() check.

  • 2
    with css will be entered case sensitive. only will be shown without. - Grundy
  • The option with the keyup event keyup not very good, because since it overwrites the value of input , the focus will constantly shift to the last character. - Stepan Kasyanenko
  • Perhaps it is not good, but this method uses the VC for example, which is why it was advised - Yaroslav Molchan