How to handle the event of pressing a button only if a letter or a number or a punctuation mark is pressed when pressing a Russian or English layout?

  • 2
    [a-zA-Zа-яА-Я \ d.,] - Sultanov Shamil
  • You can't get event.keyCode with characters here ... you need to monitor event.keyCode codes. And they can very ambiguously depend on the layout - DNS
  • Sultanov Shamil, thank you! - Iren
  • DNS, yes, thanks! - Iren

1 answer 1

We catch clicking we translate the code into a symbol and apply regexp as usual:

 $(document).on("keypress", function (e) { var _event = e || window.event; var key = _event.keyCode || _event.which; console.log(key); key = String.fromCharCode(key); console.log(key); if(/[a-zA-Zа-яА-Я\d.,]/.test(key)) { console.log('success'); //тут триггер на нажатие кнопки итд } });