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?
1 answer
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'); //тут триггер на нажатие кнопки итд } }); |
event.keyCodewith characters here ... you need to monitorevent.keyCodecodes. And they can very ambiguously depend on the layout - DNS