How to prevent invalid characters from being typed into input fields

后端 未结 7 1752
猫巷女王i
猫巷女王i 2020-11-29 10:11

Onkeydown, I run the following JavaScript:

function ThisOnKeyDown(el) {
   if (el.title == \'textonly\') {
       !(/^[A-Za-zÑñ-\\s]*$/i).test(e         


        
7条回答
  •  攒了一身酷
    2020-11-29 10:43

    Run your code against the onkeyup event and not the onkeydown event. This way you can access the result of the very last keystroke where as the onkeyup event executes as a key is pressed without knowing its result.

提交回复
热议问题