The problem with keypress
is that it will not recognize if the data comes from other sources, ie it will not work with Ctrl + V or with the right click of the mouse.
I first recommend using .on('input')
and instead of having to check character by character:
String.fromCharCode(!e.charCode ? e.which : e.charCode)
You can simply use .replace
in .val()
or .value
So:
$('#bot').on('input', function (e) {
this.value = this.value.replace(/['"]/g, "");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Digite algo: <textarea id='bot'></textarea>
This will work when you type and when you use Ctrl + V, you will not need to add all events, such as:
-
.on('keypress')
-
.on('paste')