1
I have the following Javascript:
function validaCaracteres(strToReplace) {
strSChar = "áàãâäéèêëíìîïóòõôöúùûüçÁÀÃÂÄÉÈÊËÍÌÎÏÓÒÕÖÔÚÙÛÜÇ";
strNoSChars = "aaaaaeeeeiiiiooooouuuucAAAAAEEEEIIIIOOOOOUUUUC";
var newStr = "";
for (var i = 0; i < strToReplace.length; i++) {
if (strSChar.indexOf(strToReplace.charAt(i)) != -1) {
newStr += strNoSChars.substr(strSChar.search(strToReplace.substr(i, 1)), 1);
} else {
newStr += strToReplace.substr(i, 1);
}
}
return newStr.replace(/[^a-zA-Z 0-9]/g, '').toUpperCase();
}
Its purpose is to remove the special characters at typing time, special characters, accents and if the String is lowercase return it uppercase at typing time.
However, the following error occurs, it works different in certain browsers, such as IE, it does not allow positioning inside the String, sending to the last position of the String, does not allow the reissue of the Text.
I need that if the text is typed wrong have the option to re-edit it.
Is there any way to do that ?
I’m calling this function that way:
<h:inputText value="#{manBean.manVO.field}"
onblur="this.value = validaCaracteres(this.value);"
onkeyup="this.value = validaCaracteres(this.value);"
onkeydown="this.value = validaCaracteres(this.value);"/>
Is there any other way to do this and can use the rewriting of the text ?
Thanks in advance !
Boy, I think that code must have been rolling for about 10 years on the net...
– DontVoteMeDown
Do you know any who do that too ? the way I need to ?
– Edson Cezar
In that reply has two demos, in the second shows how to enable navigation through the field.
– DontVoteMeDown