I have a search field for words in english (dictionary style). This code makes sure it only accepts terms with letters and no special chars.
$('#q').keyup(function(){
$(this).val($(this).val().replace(/[^a-zA-Z ]/g,function(str){return '';}));
});
Recently i also had to implement a words-in-spanish search field. I should only accept a-z A-Z and of course these as well:
ñáéíóúü
ÑÁÉÍÓÚ
That’s it. Any ideas? Thanks.
You can use flag
ifor case insensitivite regexp.. I just added your special characters to it.