My code for blocking characters looks like this:
$('#nome').on('keypress', function() {
var regex = new RegExp("^[ 0-9a-zA-Zàèìòùáéíóúâêîôûãõ\b]+$");
var _this = this;
// Curta pausa para esperar colar para completar
setTimeout( function(){
var texto = $(_this).val();
if(!regex.test(texto))
{
$(_this).val(texto.substring(0, (texto.length-1)))
}
}, 100);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type='text' id='nome'/>
I want to know if there is any way to block special characters, but allowing the use of hyphen - )