spatiere master
[validatoare.git] / php / cnp.php
blob:a/php/cnp.php -> blob:b/php/cnp.php
--- a/php/cnp.php
+++ b/php/cnp.php
@@ -1,7 +1,6 @@
 <?php
 
 /*
-
 Validare de CNP
 
 1) se calculeaza suma
@@ -12,31 +11,29 @@
 - rest<10 at c(13)=rest
 sau
 - rest=10 at c(13)=1
+*/
 
+function verificaCNP ($cnp) {
+	if ( strlen ($cnp) != 13 ) {
+		return false;
+	}
 
-*/
+	$s = $cnp{0}*2+$cnp{1}*7+$cnp{2}*9+$cnp{3}*1+$cnp{4}*4+$cnp{5}*6+$cnp{6}*3+$cnp{7}*5+$cnp{8}*8+$cnp{9}*2+$cnp{10}*7+$cnp{11}*9;
+	$rest = $s%11;
+	if ( $rest >= 10 ) $rest=1;
+	if ( $cnp{12} == $rest ) {
+		return true;
+	} else {
+		return false;
+	}
+}
 
 $cnp = "2851210278792";
 
 if ( verificaCNP ( $cnp ) ) {
-    echo $cnp." e valid";
+	echo $cnp." e valid";
 } else {
-    echo $cnp." e invalid";
-}
-
-function verificaCNP ($cnp) {
-    if ( strlen ($cnp) != 13 ) {
-        return false;
-    }
-    
-    $s = $cnp{0}*2+$cnp{1}*7+$cnp{2}*9+$cnp{3}*1+$cnp{4}*4+$cnp{5}*6+$cnp{6}*3+$cnp{7}*5+$cnp{8}*8+$cnp{9}*2+$cnp{10}*7+$cnp{11}*9;
-    $rest = $s%11;
-    if ( $rest >= 10 ) $rest=1;
-    if ( $cnp{12} == $rest ) {
-        return true;
-    } else {
-        return false;
-    }
+	echo $cnp." e invalid";
 }
 
 ?>

comments