[java-list] Validação de Campos!!!

2000-10-28 Por tôpico Vinícius Rodrigues Ferreira




Olá galera do mundo Java!!!
Estou necessitando validar esses campos, numa 
página html:

  CNPJ - Cadastro Nacional de Pessoa Jurídica 
  (99.999.999/-99 )
  CPF - Cadastro Pessoa Física 
  (999.999.999-99)
  Senha - ()
Por favor,aguardo resposta! 
Atenciosamente. 



Re: [java-list] Validação de Campos!!!

2000-10-27 Por tôpico Sven van 't Veer



 Vinícius Rodrigues Ferreira wrote:
 
 Olá galera do mundo Java!!!
 Estou necessitando validar esses campos, numa página html:
 
* CNPJ - Cadastro Nacional de Pessoa Jurídica (99.999.999/-99 )
* CPF - Cadastro Pessoa Física (999.999.999-99)
* Senha - ()
 
 Por favor, aguardo resposta!   Atenciosamente.
script language="JavaScript"
//
function CheckForChars(valor){
   key = valor.substr(valor.length-1);
   if(!("0123456789".indexOf(key) = 0)){
document.entrada["key"].value = valor.substr(0, valor.length-1);
alert("CNPJ/CPF somente pode conter numeros." );
   }
}

function CheckForCharsTelefone(valor){
   key = valor.substr(valor.length-1);
   if(!("0123456789".indexOf(key) = 0)){
document.entrada["key"].value = valor.substr(0, valor.length-1);
alert("Telefone somente pode conter numeros." );
   }
}

function checkTelefone(){
  if (document.entrada["telefone"].value != ""){
valor = document.entrada["telefone"].value;
if (!(valor.substring(0, 1) == "0")){
  alert("Favor informa DDD iniciando com 0!");
  return false;
}
if (valor.length != 10  valor.length != 11){
  alert("Telefone deve ser informado com 10 ou 11 digitos!");
  return false;
} else {
  return true;
}
  } else {
return true;
  }
}

function checkInput(){
  telef = checkTelefone();
  cgc = checkCgcCpf();
  if (document.entrada['canPost'].value == "false"){
alert("Consulta já está sendo efeituado!");
  return false;
  } else if  (telef== true  cgc == true){
  document.entrada['canPost'].value = 'false';
return true;
  }
  return false;
}

function checkCgcCpf(){
   teste = false;
   if (document.entrada["key"].value!="") {
   teste = true;
  valor = document.entrada["key"].value;
  if (valor.length==11){
  if (!ChecaCPF(valor)) {
  alert("CNPJ/CPF inválido!");
  return (false);
  }
  } else {
  if (valor.length==14){
 if (!ChecaCGC(valor)) {
alert("CNPJ/CPF inválido!");
return (false);
 }
 } else {
  alert("CNPJ/CPF inválido!");
  return (false);
 }
  }
   } else {
alert("CNPJ/CPF inválido!");
  return (false);
   }
   return (true);
}

function ValChar(ch) {
if (ch=="0") return 0
else if (ch=="1") return 1
else if (ch=="2") return 2
else if (ch=="3") return 3
else if (ch=="4") return 4
else if (ch=="5") return 5
else if (ch=="6") return 6
else if (ch=="7") return 7
else if (ch=="8") return 8
else if (ch=="9") return 9
else return 10
}

//Verifica se o argumento é um CPF válido
function ChecaCPF (CKCPF) {
var CPF = CKCPF;
var NewCPF = "";
//Verifica tamanho do CPF
if (CPF.length!=11) {
return false;
}
//Calcula os dígitos verificadores
//Guarda os 09 primeiros digitos
var DVCPF = CPF.substring(0,9);
var s1 = 0
for (i=1;i=9;i++) s1 = s1 + (ValChar(DVCPF.charAt(i-1))*(11-i))
r1 = s1 % 11
if (r12) dv1=0
else dv1 = 11 - r1
var s2 = dv1*2
for (i=1;i=9;i++) s2 = s2 + (ValChar(DVCPF.charAt(i-1))*(12-i))
r2 = s2 % 11
if (r22) dv2=0
else dv2 = 11 - r2
var DV = ""
DV = DV + dv1 + dv2
var NewDV = CPF.substring(9,11)
if (NewDV==DV) return true
else {
return false
}
}

/*
function ChecaSubmitC() {
teste = false;
if (document.frmPri["tbrddocemicpfcgc"].value!="") {
teste = true;
if (!ChecaCPF(document.frmPri["tbrddocemicpfcgc"].value)) {
alert("CGC/CPF inválido!");
return (false);
}
}
return (teste);
} */

//Verifica se o argumento é um CGC válido de 8 dígitos
function ChecaCGC8 (CKCGC) {
var CGC = CKCGC;
var NewCGC = "";
//Elimina todos os espaços, pontos, barras e traços do CGC
for (i=0;iCGC.length;i++) { //
if (CGC.charAt(i) != " "  CGC.charAt(i) != "."  CGC.charAt(i) !=
"/"  CGC.charAt(i) != "-") NewCGC = NewCGC + CGC.charAt(i);
}
//Verifica tamanho do CGC
if (NewCGC.length!=8) {
return false;
}
//verifica se todos os caracteres são numéricos
var Numerico = false;
var Numeros = "0123456789";
for (i=0;iNewCGC.length;i++) { //
Numerico = false;
for (j=0;jNumeros.length;j++) { //
if (NewCGC.charAt(i) == Numeros.charAt(j)) {
Numerico = true;
break;
}
}
if (!Numerico) {
return false;
}
}
//Calcula os dígitos verificadores
var s1 = 0;
aux = 0;
soma = 0
for (i=1;i=8;i++) {
//alert("i="+i+" - char(i-1)="+NewCGC.charAt(i-1));
aux = (ValChar(NewCGC.charAt(i-1)))*((i % 2)+1);
//alert ("aux="+aux);
if (aux9) aux = aux-9;
//alert ("aux="+aux);
soma = soma + aux;
}
r1 = soma % 10;