Created
July 13, 2010 12:44
-
-
Save dpavlin/473799 to your computer and use it in GitHub Desktop.
validate JMBG
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
#!/usr/bin/perl | |
use warnings; | |
use strict; | |
sub valid_jmbg { | |
my $jmbg = shift; | |
return 0 unless $jmbg =~ /^\d{13}$/; | |
my @c = split(//, $jmbg); | |
my $S=0; | |
for (my $i=0;$i<6;$i++){ | |
$S+= (7-$i)*($c[$i]+$c[6+$i]); | |
} | |
print "$jmbg "; | |
my $checksum = 11-($S%11); | |
if ( $checksum == $c[12] ) { | |
print "OK\n"; | |
} else { | |
print "ERROR [$checksum]\n"; | |
} | |
} | |
valid_jmbg($_) foreach @ARGV; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More information at: http://en.wikipedia.org/wiki/Unique_Master_Citizen_Number