I'm trying to add a mask to a field to accept only alphabetic characters.
Apparently I was able to find a solution .
Code
$(function () {
$("#name").keypress( function(key) {
if((key.charCode < 97 || key.charCode > 122) && (key.charCode < 65 || key.charCode > 90) && key.charCode != 32 ) {
return false;
}
});
});
So far, it works cool, it only accepts letters ( [a-zA-Z]
) and espaço
only.
But the bizarre that after entering any sequence of letters, after giving espaço
twice appears a ponto
of nothing.
If I try to explicitly prohibit the permission of ponto
including key.charCode == 46
in if
buga everything and accepts any type of character.
Does anyone have any idea how to make it work correctly?