The problem of keypress
is that will not recognize if the data comes from other sources, IE, will not work with Ctrl+V or right mouse click.
I recommend first use .on('input')
and instead of having to check character by character:
String.fromCharCode(!e.charCode ? e.which : e.charCode)
You can just use .replace
in the .val()
or .value
Thus:
$('#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 way it will work when typing and when using Ctrl+V, you will not need to add all events such as:
.on('keypress')
.on('paste')
was faster than me, +1 good :)
– Homer Simpson
@If you have another suggestion, different of course, that also solves does not exist in reply :D can guarantee a few dots and still help many users.
– Guilherme Nascimento
@Guillhermenascimento resolves "much simpler" even.
– NoobSaibot