I’m trying to implement a functionality where if a user pastes text it should remove <>$ and ! while
function specialCharRestriction(){
setTimeout(function(e){
$('input, textarea').bind("cut copy paste",function(e) {
e.preventDefault();
});
$('input:not([type=password]), textarea').on('keypress', function (e) {
var blockSpecialRegex = /[!$(){}[]:;<+?\>]/;
var key = String.fromCharCode(!e.charCode ? e.which : e.charCode);
console.log(key);
if(blockSpecialRegex.test(key)){
e.preventDefault();
return false;
}
});
}, 500);
}
The above code works on all inputs on page or a dom. Currently it disables the paste function, however I want something like this:
$('input').val().replace(regex, '')
so that it can be applied on all inputs and I don’t have to select all the inputs one by one. There are more than 100 fields declared in my project so pls help with a generic code which can be applied on all input fields.