Changeset 355 for trunk/expressoAdmin1_2/inc/class.functions.inc.php
- Timestamp:
- 07/18/08 11:36:30 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/expressoAdmin1_2/inc/class.functions.inc.php
r317 r355 747 747 return $key . '*'; 748 748 } 749 750 751 function checkCPF($cpf) 752 { 753 $nulos = array("12345678909","11111111111","22222222222","33333333333", 754 "44444444444","55555555555","66666666666","77777777777", 755 "88888888888","99999999999","00000000000"); 756 757 /* Retira todos os caracteres que nao sejam 0-9 */ 758 $cpf = ereg_replace("[^0-9]", "", $cpf); 759 760 /*Retorna falso se houver letras no cpf */ 761 if (!(ereg("[0-9]",$cpf))) 762 return false; 763 764 /* Retorna falso se o cpf for nulo */ 765 if( in_array($cpf, $nulos) ) 766 return false; 767 768 /*Calcula o penúltimo dígito verificador*/ 769 $acum=0; 770 for($i=0; $i<9; $i++) 771 { 772 $acum+= $cpf[$i]*(10-$i); 773 } 774 775 $x=$acum % 11; 776 $acum = ($x>1) ? (11 - $x) : 0; 777 /* Retorna falso se o digito calculado eh diferente do passado na string */ 778 if ($acum != $cpf[9]){ 779 return false; 780 } 781 /*Calcula o último dígito verificador*/ 782 $acum=0; 783 for ($i=0; $i<10; $i++) 784 { 785 $acum+= $cpf[$i]*(11-$i); 786 } 787 788 $x=$acum % 11; 789 $acum = ($x > 1) ? (11-$x) : 0; 790 /* Retorna falso se o digito calculado eh diferente do passado na string */ 791 if ( $acum != $cpf[10]) 792 { 793 return false; 794 } 795 /* Retorna verdadeiro se o cpf eh valido */ 796 return true; 797 } 749 798 } 750 799
Note: See TracChangeset
for help on using the changeset viewer.