This little snippet will validate a passed ABA number. If invoked without an ABA parameter, it will validate a test suite of the 10 possible check-digits. These should all pass.
#!/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; }

Replies are listed 'Best First'.
RE: ABA validator
by lhoward (Vicar) on Jun 12, 2000 at 21:52 UTC
    I wanted to add a quick note that (unless I'm reading this wrong) an ABA number is an American Banking Association number. It is used to uniquely identify US banks. It is the number on the lower-left hand corner of US checks. It can also be referred to as a Transit Routing Code in wire transfer circles.