How to prevent invalid characters from being typed into input fields

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

    The above code does it says- allows ONLY numbers. You can modify it by adding exception to say BACKSPACE for example like this

    
        
            
            
            
            
        
            
        
    
    

提交回复
热议问题