How to prevent invalid characters from being typed into input fields

后端 未结 7 1761
猫巷女王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:41

    You could easily do this in a single html line.

    Like this to disallow spaces:

    
    

    Or this to only allow numbers:

    
    

    Just look up the unicode of any numbers you want to allow or disallow.

提交回复
热议问题