#!/usr/local/bin/perl use strict; # either pass a potential ABA number, or just invoke without passing # invoking without a passed ABA number will validate the ABA routine i +tself # by reporting all 10 numbers in included test suite (they should all +be valid) my $passed_aba = shift; my @aba_nos; if (length($passed_aba) gt 0 ) { push(@aba_nos,$passed_aba); } else { # the following represents a test suite of the 10 possible configura +tions @aba_nos = qw/ 221012181 231511232 091904513 063100264 051400125 071 +012166 063100277 067006238 063102149 263105250/; } my $aba; for $aba ( @aba_nos ) { if ( aba($aba) ) { print "\n", "$aba is valid"; } else { print "\n", "$aba is not a valid ABA"; } } exit; sub aba { my $EFTABA = shift; my $retval = 0; my $sum = 0; my ($lastpos, $checkdigit, $checksum); my @aba = split(//,$EFTABA); # now do some math using weighing factor # position 1 2 3 4 5 6 7 8 # weight 3 7 1 3 7 1 3 7 $sum += ($aba[0] * 3); $sum += ($aba[1] * 7); $sum += ($aba[2] * 1); $sum += ($aba[3] * 3); $sum += ($aba[4] * 7); $sum += ($aba[5] * 1); $sum += ($aba[6] * 3); $sum += ($aba[7] * 7); # now the total gets subtracted from the next highest multiple of 10 # (just subtract the last digit from 10....) # print "\nSum: $sum"; $lastpos = length($sum); $checkdigit = substr($sum,($lastpos-1),1); # print "\nCheckdigit: $checkdigit"; $checksum = ( 10 - $aba[8] ); if ( $checksum eq 10 ) # 10 = 0 { $checksum = 0; } if ( $checksum eq $checkdigit ) { $retval = 1; #print "\n$EFTABA is a valid ABA number"; } return $retval; }
In reply to ABA validator by wardk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |