Search blogs
Did you find a problem ? Tell us about it! Get a blog Report blog Random blog

CNP

Posted on 10/04/2006

/*

Validare de CNP

1) se calculeaza suma
s:=c(1)*2+c(2)*7+c(3)*9+c(4)*1+c(5)*4+c(6)*6+c(7)*3+c(8)*5+c(9)*8+c(10)*2+c(11)*7+c(12)*9
2) faci impartirea
rest=s%11
3) dupa cum:
- rest<10 at c(13)=rest
sau
- rest=10 at c(13)=1


*/

$cnp = "";

if ( calcCNP ( $cnp ) ) {
echo $cnp." e valid";
} else {
    echo $cnp." e invalid";
}

function calcCNP ($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 ( $cnp{12} == $rest ) {
return TRUE;
} else {
        return FALSE;
}
}
Tags: cnp , javascript
These icons link to social bookmarking sites where readers can share and discover new web pages. Bookmark page
  • digg
  • del.icio.us
  • YahooMyWeb
  • Furl
  • Fark
  • Ma.gnolia
  • Reddit
  • Smarking
  • Spurl
  • NewsVine
  • blinkbits
  • Yahoo Messenger
Razvan @ 15:07
Filed under: opensource

No comments have been added to this post yet.

No trackbacks have been added to this post yet.

Leave a comment





Human test

Information for comment users
Your e-mail address is never displayed. Please consider what you're posting.