Created
February 1, 2015 06:03
-
-
Save bran921007/88f9042ce2ca9fb3cd7b to your computer and use it in GitHub Desktop.
PHP: Validas DNI espanol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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