2
I have a javascript function that doesn’t let write numbers, only letters, in Chrome it works exactly as it is proposed, now in Mozilla it doesn’t work, below my function:
function soletra(event) {
var value = String.fromCharCode(event.which);
var pattern = new RegExp(/^[a-záàâãéèêíïóôõöúçñ ]+$/i);
return pattern.test(value);
}
I made an adaptation to work, but it was not good that leaves some keys inactive if the field is in focus:
function soletra(event) {
if(event.keyCode == 9 || event.keyCode == 8 || event.keyCode == 46
|| event.keyCode == 39 ||event.keyCode == 37 || event.keyCode == 38 || event.keyCode == 40)
return;
var value = String.fromCharCode(event.which);
var pattern = new RegExp(/^[a-záàâãéèêíïóôõöúçñ ]+$/i);
return pattern.test(value);
}
and the call of function is like this:
$("#id").bind("keypress paste drop", soletra);
I’m trying to implement this line, but it continue to work in the same way thanks for the help in relation to doc
– Bruno H.
@Brunoh here you can see a functional example: https://jsfiddle.net/jamfLktj/ and I also put an example in the answer
– Ricardo Pontual