Validar Cpf Em Ajax
Started By w1ck3dr0x, 15/09/2006, 13:09
9 replies to this topic
#1
Posted 15/09/2006, 13:09
Ae galera....queria uma ajuda de vcs
alguém tem o código dessa validação?
tenho q montar isso numa página...e tem q ser em Ajax
=/
tenso esse assunto
alguém tem o código dessa validação?
tenho q montar isso numa página...e tem q ser em Ajax
=/
tenso esse assunto
#3
Posted 22/09/2006, 13:20
eu tenho uma funçãozinha em php pra isso, vo postar ela aqui, a parte de ajax se faz ne, se naum conseguir fala q eu ajudo.
<? /** * Função que valida CPF * Retorna False para cpfs inválidos e true para verdadeiros * * @param string $cpf * @return boolean */ function validaCPF ($cpf) { if ( !is_numeric($cpf) ) { return false; } else { if( ($cpf == '11111111111') || ($cpf == '22222222222') || ($cpf == '33333333333') || ($cpf == '44444444444') || ($cpf == '55555555555') || ($cpf == '66666666666') || ($cpf == '77777777777') || ($cpf == '88888888888') || ($cpf == '99999999999') || ($cpf == '00000000000') ) { return false; } else { $digVerficadorInfo = substr( $cpf, 9, 2 ); for($i=0; $i<=8; $i++) { $digCpf[$i] = substr($cpf, $i,1); } $posDigito = 10; $valSoma = 0; for($i=0; $i<=8; $i++) { $valSoma = $valSoma + $digCpf[$i] * $posDigito; $posDigito = $posDigito - 1; } $digCpf[9] = $valSoma % 11; if ( $digCpf[9] < 2 ) { $digCpf[9] = 0; } else { $digCpf[9] = 11 - $digCpf[9]; } $posDigito2 = 11; $valSoma2 = 0; for($i=0; $i<=9; $i++) { $valSoma2 = $valSoma2 + $digCpf[$i] * $posDigito2; $posDigito2 = $posDigito2 - 1; } $digCpf[10] = $valSoma2 % 11; if ( $digCpf[10] < 2 ) { $digCpf[10] = 0; } else { $digCpf[10] = 11 - $digCpf[10]; } $digVerficador = $digCpf[9] * 10 + $digCpf[10]; if ( $digVerficador != $digVerficadorInfo ) { return false; } else { return true; } } } } ?>
Edição feita por: Tobias, 22/09/2006, 13:20.
#4
Posted 29/09/2006, 09:28
Opa,
Não sei se estou respondendo um pouco tarde... mas esta aí..
Validando CNPJ/CPF utilizando a biblioteca XAJAX
Att
Não sei se estou respondendo um pouco tarde... mas esta aí..
Validando CNPJ/CPF utilizando a biblioteca XAJAX
<?php // Include com a classe XAjax include_once("xajax.inc.php"); // Instancia o xajax object $xajax = new xajax($_SERVER['PHP_SELF']); // function valida_CPF($cpf) { $RecebeCPF=$cpf; $s=""; for ($x=1; $x<=strlen($RecebeCPF); $x=$x+1) { $ch=substr($RecebeCPF,$x-1,1); if (ord($ch)>=48 && ord($ch)<=57) { $s=$s.$ch; } } $RecebeCPF=$s; if (!is_numeric($RecebeCPF)) { return 0; } if (strlen($RecebeCPF)!=11) { return 0; } else if ($RecebeCPF=="00000000000") { return 0; } else { $Numero[1]=intval(substr($RecebeCPF,1-1,1)); $Numero[2]=intval(substr($RecebeCPF,2-1,1)); $Numero[3]=intval(substr($RecebeCPF,3-1,1)); $Numero[4]=intval(substr($RecebeCPF,4-1,1)); $Numero[5]=intval(substr($RecebeCPF,5-1,1)); $Numero[6]=intval(substr($RecebeCPF,6-1,1)); $Numero[7]=intval(substr($RecebeCPF,7-1,1)); $Numero[8]=intval(substr($RecebeCPF,8-1,1)); $Numero[9]=intval(substr($RecebeCPF,9-1,1)); $Numero[10]=intval(substr($RecebeCPF,10-1,1)); $Numero[11]=intval(substr($RecebeCPF,11-1,1)); $soma=10*$Numero[1]+9*$Numero[2]+8*$Numero[3]+7*$Numero[4]+6*$Numero[5]+5* $Numero[6]+4*$Numero[7]+3*$Numero[8]+2*$Numero[9]; $soma=$soma-(11*(intval($soma/11))); if ($soma==0 || $soma==1) { $resultado1=0; } else { $resultado1=11-$soma; } if ($resultado1==$Numero[10]) { $soma=$Numero[1]*11+$Numero[2]*10+$Numero[3]*9+$Numero[4]*8+$Numero[5]*7+$Numero[6]*6+$Numero[7]*5+ $Numero[8]*4+$Numero[9]*3+$Numero[10]*2; $soma=$soma-(11*(intval($soma/11))); if ($soma==0 || $soma==1) { $resultado2=0; } else { $resultado2=11-$soma; } if ($resultado2==$Numero[11]) { return 1; } else { return 0; } } else { return 0; } } } // function valida_CNPJ($cnpj) { $RecebeCNPJ=${"cnpj"}; $s=""; for ($x=1; $x<=strlen($RecebeCNPJ); $x=$x+1) { $ch=substr($RecebeCNPJ,$x-1,1); if (ord($ch)>=48 && ord($ch)<=57) { $s=$s.$ch; } } $RecebeCNPJ=$s; if (strlen($RecebeCNPJ) > 14) { while (strlen($RecebeCNPJ) != 14) { if (!intval(substr($RecebeCNPJ, 0,1))) { $RecebeCNPJ = substr($RecebeCNPJ, 1); } else { return 0; } } } if (!is_numeric($RecebeCNPJ)) { return 0; } if (strlen($RecebeCNPJ)!=14) { return 0; } else if ($RecebeCNPJ=="00000000000000") { return 0; } else { $Numero[1]=intval(substr($RecebeCNPJ,1-1,1)); $Numero[2]=intval(substr($RecebeCNPJ,2-1,1)); $Numero[3]=intval(substr($RecebeCNPJ,3-1,1)); $Numero[4]=intval(substr($RecebeCNPJ,4-1,1)); $Numero[5]=intval(substr($RecebeCNPJ,5-1,1)); $Numero[6]=intval(substr($RecebeCNPJ,6-1,1)); $Numero[7]=intval(substr($RecebeCNPJ,7-1,1)); $Numero[8]=intval(substr($RecebeCNPJ,8-1,1)); $Numero[9]=intval(substr($RecebeCNPJ,9-1,1)); $Numero[10]=intval(substr($RecebeCNPJ,10-1,1)); $Numero[11]=intval(substr($RecebeCNPJ,11-1,1)); $Numero[12]=intval(substr($RecebeCNPJ,12-1,1)); $Numero[13]=intval(substr($RecebeCNPJ,13-1,1)); $Numero[14]=intval(substr($RecebeCNPJ,14-1,1)); $soma=$Numero[1]*5+$Numero[2]*4+$Numero[3]*3+$Numero[4]*2+$Numero[5]*9+$Numero[6]*8+$Numero[7]*7+ $Numero[8]*6+$Numero[9]*5+$Numero[10]*4+$Numero[11]*3+$Numero[12]*2; $soma=$soma-(11*(intval($soma/11))); if ($soma==0 || $soma==1) { $resultado1=0; } else { $resultado1=11-$soma; } if ($resultado1==$Numero[13]) { $soma=$Numero[1]*6+$Numero[2]*5+$Numero[3]*4+$Numero[4]*3+$Numero[5]*2+$Numero[6]*9+ $Numero[7]*8+$Numero[8]*7+$Numero[9]*6+$Numero[10]*5+$Numero[11]*4+$Numero[12]*3+$Numero[13]*2; $soma=$soma-(11*(intval($soma/11))); if ($soma==0 || $soma==1) { $resultado2=0; } else { $resultado2=11-$soma; } if ($resultado2==$Numero[14]) { return 1; } else { return 0; } } else { return 0; } } } // function processForm($dados) { $objResponse = new xajaxResponse(); $erro_cpf = valida_CPF($dados['cpf']); $erro_cnpj = valida_CNPJ($dados['cnpj']); if($erro_cpf == 0) { $objResponse->addAssign("erro_cpf","innerHTML","CPF Invalido"); $objResponse->addScript("document.getElementById('cpf').focus();"); $objResponse->addScript("document.getElementById('cpf').style.color = 'red';"); $objResponse->addAssign("erro","innerHTML",""); } else if($erro_cnpj == 0) { $objResponse->addAssign("erro_cnpj","innerHTML","CNPJ Invalido"); $objResponse->addScript("document.getElementById('cnpj').focus();"); $objResponse->addScript("document.getElementById('cnpj').style.color = 'red';"); $objResponse->addAssign("erro","innerHTML",""); } else { $objResponse->addAssign("erro","innerHTML","Dados conferidos, OK..."); $objResponse->addAssign("erro_cpf", "innerHTML", ""); $objResponse->addAssign("erro_cnpj", "innerHTML", ""); } return $objResponse->getXML(); } // Registra a Funcao $xajax->registerFunction("processForm"); // Processa as requisicoes $xajax->processRequests(); ?> <html> <head> <title>Documento sem título</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <? // Coloca os JavaScripts necessários para o XAjax $xajax->printJavascript(); ?> </head> <body> <form name="valida" id="valida" action="java script://"> <div class="rotulo">CPF:</div> <div class="campo"><input autocomplete="off" type="text" id="cpf" name="cpf" value="" maxlength="255" /></div> <div class="campo" id="erro_cpf" name="erro"> </div> <br> <div class="rotulo">CNPJ:</div> <div class="campo"><input autocomplete="off" type="text" id="cnpj" name="cnpj" value="" maxlength="255"/></div> <div class="campo" id="erro_cnpj" name="erro"> </div> <br> <button onclick="java script:xajax_processForm(xajax.getFormValues('valida'));">Validar!</button> <div class="campo" id="erro" name="erro"> </div> </form> </body> </html>
Att
#5
Posted 21/09/2017, 19:23
Cialis GÐ ÑСÂnstig Kaufen 40mg viagra cialis Vejiga Propecia
Dosage Of Keflex For Children Pharmacy Escrow Refills Propecia Ricrescita
Levothyroxine Without Us Prescription cialis Online Lasix Buy
Dosage Of Keflex For Children Pharmacy Escrow Refills Propecia Ricrescita
Levothyroxine Without Us Prescription cialis Online Lasix Buy
#6
Posted 06/10/2017, 05:49
Viagra Acheter France Medicamento Cialis Precio Propecia Pas Cher Livraison Rapide generic levitra 20mg Propecia Time Results Which Family Medications Is Amoxicillin Generique Levitra
Prix Du Levitra 10 Minimum Garanti Cialis In Svizzera Buy Viagranext Day Delivery levitra prices Viagra Ordering From India
Prix Du Levitra 10 Minimum Garanti Cialis In Svizzera Buy Viagranext Day Delivery levitra prices Viagra Ordering From India
#7
Posted 13/10/2017, 17:25
Propecia Amenorrea viagra Is Lasix A Blood Thinner Prix Vente Xenical Pharmacie
Generic Levitra For Sale Preis Cialis 10 Cialis Dapoxetine Expedition Durant La Nuit cialis buy online Canadian Medicines Online Quando Cialis Non Funziona
Generic Levitra For Sale Preis Cialis 10 Cialis Dapoxetine Expedition Durant La Nuit cialis buy online Canadian Medicines Online Quando Cialis Non Funziona
#9
Posted 22/11/2017, 11:33
Kamagra 100mg Villeurbanne Prix En Pharmacie Du Levitra Online Amoxil viagra Flagyl Pills Order
Walking Pneumonia Zithromax viagra online Stendra Internet In Us
Zithromax Discount Coupons Keflex For Strep Throat viagra Lowest Priced Super Avana
Walking Pneumonia Zithromax viagra online Stendra Internet In Us
Zithromax Discount Coupons Keflex For Strep Throat viagra Lowest Priced Super Avana
0 user(s) are reading this topic
0 membro(s), 0 visitante(s) e 0 membros anônimo(s)