Skip to content

Instantly share code, notes, and snippets.

@bran921007
Created February 1, 2015 06:03
Show Gist options
  • Save bran921007/88f9042ce2ca9fb3cd7b to your computer and use it in GitHub Desktop.
Save bran921007/88f9042ce2ca9fb3cd7b to your computer and use it in GitHub Desktop.
PHP: Validas DNI espanol
function validar_dni($dni){
$letra = substr($dni, -1);
$numeros = substr($dni, 0, -1);
if ( substr("TRWAGMYFPDXBNJZSQVHLCKE", $numeros%23, 1) == $letra && strlen($letra) == 1 && strlen ($numeros) == 8 ){
echo 'valido';
}else{
echo 'no valido';
}
}
validar_dni('73547889F'); // válido
validar_dni('73547889M'); // no válido
validar_dni('73547889'); // no válido
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment