Skip to content

Instantly share code, notes, and snippets.

@dpavlin
Created July 13, 2010 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpavlin/473799 to your computer and use it in GitHub Desktop.
Save dpavlin/473799 to your computer and use it in GitHub Desktop.
validate JMBG
#!/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;
@dpavlin
Copy link
Author

dpavlin commented Jul 13, 2010

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment