if(!function_exists('validaCpf')){ /** Valida CPF (dígitos verificadores); aceita com ou sem máscara. */ function validaCpf($cpf){ $cpf = preg_replace('/\D+/', '', (string) $cpf); if(strlen($cpf) !== 11 || preg_match('/^(\d)\1{10}$/', $cpf)) return false; for($t = 9; $t < 11; $t++){ $soma = 0; for($i = 0; $i < $t; $i++) $soma += $cpf[$i] * (($t + 1) - $i); $dv = ((10 * $soma) % 11) % 10; if((int) $cpf[$t] !== $dv) return false; } return true; } }