I am creating a system in which the user must type in an input the name of the mother with only alphanumeric characters. I'm using the code below that is working, but I noticed a flaw. Even allowing not to enter other special characters, if the user copy and paste another special character it will be inserted into the input.
<input type="text" id="nomeMae">
$('#nomeMae').bind('keypress', function (event)
{
var regex = new RegExp("^[0-9a-zA-Z\b]+$");
var key = String.fromCharCode(!event.charCode ? event.which : event.charCode);
if (!regex.test(key))
{
event.preventDefault();
return false;
}
});