0
Good morning, I wanted a mask for a text box where the user can only insert letters and letters with accents.
The code I could find just lets you insert letters without accents.
function lettersOnly(evt) {
evt = (evt) ? evt : event;
var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
if (charCode == 32)
return true;
if (charCode > 31 && (charCode < 65 || charCode > 90) && (charCode < 97 || charCode > 122)) {
return false;
}
else
return true;
}
The variable 'evt' is the letter pressed, that is, in the textbox I am using the property onkeypress="return lettersOnly(event)"
.
Friend, you can use REGEX, follow the link to help: https://stackoverflow.com/questions/3617797/regex-to-match-only-letters
– Maycon F. Castro