-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex3.php
More file actions
67 lines (46 loc) · 1.44 KB
/
index3.php
File metadata and controls
67 lines (46 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
class Documento{
private $numero;
public function getNumero(){
return $this->numero;
}
public function setNumero($num){
$this->numero = $num;
}
public static function validarCpf($cpf):bool{
if(empty($cpf)) {
return false;
}
$cpf = preg_match('/[0-9]/', $cpf)?$cpf:0;
$cpf = str_pad($cpf, 11, '0', STR_PAD_LEFT);
if (strlen($cpf) != 11) {
echo "length";
return false;
}
else if ($cpf == '00000000000' ||
$cpf == '11111111111' ||
$cpf == '22222222222' ||
$cpf == '33333333333' ||
$cpf == '44444444444' ||
$cpf == '55555555555' ||
$cpf == '66666666666' ||
$cpf == '77777777777' ||
$cpf == '88888888888' ||
$cpf == '99999999999') {
return false;
} else {
for ($t = 9; $t < 11; $t++) {
for ($d = 0, $c = 0; $c < $t; $c++) {
$d += $cpf{$c} * (($t + 1) - $c);
}
$d = ((10 * $d) % 11) % 10;
if ($cpf{$c} != $d) {
return false;
}
}
return true;
}
}
}
var_dump(Documento::validarCpf("26171645435"));
?>