Skip to content

Instantly share code, notes, and snippets.

@marceloxp
Created July 2, 2014 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marceloxp/ca3ddacab3d09929a6d7 to your computer and use it in GitHub Desktop.
Save marceloxp/ca3ddacab3d09929a6d7 to your computer and use it in GitHub Desktop.
Validação de dados - Brasil
function valida_cpf($cpf) {if (empty($cpf)) {return false; } $cpf = preg_replace("/[^0-9]/", "", $cpf); for ($i = 0; $i <= 9; $i++) {if (str_repeat($i, 11) == $cpf) {return false; } } 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; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment