Last active
March 2, 2017 07:06
-
-
Save bandicsongor/6991128 to your computer and use it in GitHub Desktop.
Validare cnp, cnp validation, CNP validalas
This file contains 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 validare_cnp( $cnp ) | |
{ | |
$constanta = "279146358279"; | |
if ( strlen($cnp) != 13 ) | |
{ | |
return FALSE; | |
} | |
$suma = 0; | |
for ( $i = 0; $i < strlen($constanta); $i++ ) | |
{ | |
$suma += $cnp[$i] * $constanta[$i]; | |
} | |
$rest = $suma % 11; | |
if ( ( $rest < 10 && $rest == $cnp[12] ) || ($rest == 10 && $cnp[12] == 1 ) ) | |
{ | |
return TRUE; | |
} | |
return FALSE; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment