vivek vijayakumar vivek vijayakumar - 1 month ago 11
Javascript Question

block this special characters using query `~ #$^+|\ []{}<>

I want to block some special characters from entering in text box.
`~ #$^+|\ []{}<> these are the characters i would like to prevent from user inputting. Can any one suggest a solution or reg ex.

Answer

function some(){
var input = document.getElementById('one').value;
var one = input.replace(/[(\\^`~#\$\^\+\|\\\[\]{}<>)]/g,"");
document.getElementById('one').value=one;
}
 <input type="text" oninput="some()" id="one"  >

Comments