adaugat validare CNP in javascript
adaugat validare CNP in javascript

file:b/js/cnp.html (new)
--- /dev/null
+++ b/js/cnp.html
@@ -1,1 +1,31 @@
+<html>
+<head>
+<script type="text/javascript">
+    function verificaCNP ($cnp) {
+        if ( $cnp.length != 13 ) {
+            return false;
+        }
+        
+        var $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;
+        var $rest = $s%11;
+        if ( $rest >= 10 ) {$rest=1};
+        if ( $cnp[12] == $rest ) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+</script>
+</head>
+<body>
 
+<script type="text/javascript">
+    var $cnp = "2851210278792";
+    if ( verificaCNP ( $cnp ) ) {
+        alert ($cnp+" e valid");
+    } else {
+        alert ($cnp+" e invalid");
+    }
+</script>
+</body>
+</html>

comments