Boa tarde galera..
Estou tentando utilizar uma máscara em um campo do meu jsf mas não consigo.
As vezes ocorre erro e as vezes não executa nada...já tentei de várias formas...
Estou usando richfaces...
<head>
<script type="text/javascript">
oldObj = "";
oldValor = "";
inteiro = new RegExp("[0-9]");
function formaTel(obj)
{
valore = obj.value;
if(valore != oldValor || oldObj != obj){
for(i=0;i<valore.length;i++){
if(!inteiro.test(valore.charAt(i))){
valore = valore.substring(0,i) + valore.substring(i+1,valore.length);
i = -1;
}
}
if(valore.length > 4 && valore.length < 9){
valore = valore.substring(0,4) + "-" + valore.substring(4,valore.length);
}
obj.value = valore;
oldValor = valore;
oldObj = obj;
}
}
</script>
</head>
<h:inputText id="mascara" onkeypress="formaTel(this)" value="#{mascaraHome.instance.mascara}">
Alguem tem uma sugestão?