How to remove double quote use onkeyup attr inline?

322 views Asked by At

I tried

<input type="text" name="first_name" 
  onkeyup="value=value.replace(/[\-\'\.\,\/\`\:\~\!\@\#\$\%\^\&\*\(\)\_\+\=\;\|\{\}\[\]\<\>\?]/g,'')">

it works for almost all special chars, but when I add a double-quote filter like

 <input type="text" name="first_name" in first  
      onkeyup="value=value.replace(/[\"\-\'\.\,\/\`\:\~\!\@\#\$\%\^\&\*\(\)\_\+\=\;\|\{\}\[\]\<\>\?]/g,'')">

it seems to not allow to do like that. I want to custom remove the mark I want.

1

There are 1 answers

1
Mohit Bhardwaj On BEST ANSWER

You can put your code in an external function instead of placing it inline. It's just that the " interferes with the html attributes' " and break the code.

document.querySelector(".no-special-chars").addEventListener("keyup", function(){
  this.value = this.value.replace(/[\"\-\'\.\,\/\`\:\~\!\@\#\$\%\^\&\*\(\)\_\+\=\;\|\{\}\[\]\<\>\?]/g,'');
});//keyup()
<input class="no-special-chars" type="text" name="first_name" />