Mascara no meu jsf

0 respostas
D

Aee...galera tenho essa função js e naum tenho noção de como chama-la no meu jsf..

JS:
var oldObj   = "";
var oldValor = "";
var inteiro  = new RegExp("[0-9]");

function formaData(mascara)
{
	alert("teste");
  var valore = mascara;
  if(valore != oldValor || oldObj != mascara){
	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 < 1){
	  valore = "";
	}else if(valore.length > 2 && valore.length < 5){
	  valore = valore.substring(0,2) + "/" + valore.substring(2,valore.length);
	}else if(valore.length > 4 && valore.length < 6){
	  valore = valore.substring(0,2) + "/" + valore.substring(2,4) + "/" + valore.substring(4,valore.length);
	}else if(valore.length > 5 && valore.length < 9){
	  valore = valore.substring(0,2) + "/" + valore.substring(2,4) + "/" + valore.substring(4,valore.length);
	}
	mascara.value = valore;
	oldValor = valore;
	oldObj = mascara;
  }
}
//-->
Jsf:
<h:inputText id="mascara" onKeyPress="return formaData(mascara);" value="#{mascaraHome.instance.mascara}">

Alguem pode me ajudar?

Criado 29 de setembro de 2008
Respostas 0
Participantes 1