Zend - The PHP Company




Commerce

Add Code


ABA (Bank ID) Validator  

Type: code fragment
Added by: davidbhale
Entered: 19/07/2002
Last modified: 31/10/2010
Rating: - (fewer than 3 votes)
Views: 10575
This function validates the supplied ABA number using a simple mod 10 check digit routine.


<?php

function abavalidate($aba)
{
  
// First, check for 9 digits and non-numeric characters.
  
if (ereg("^[0-9]{9}$",$aba))
  {
    
$n 0;
    for (
$i 0$i 9$i += 3)
    {
      
$n += (substr($aba,$i,1) * 3)
        + (
substr($aba,$i 1,1) * 7)
        + (
substr($aba,$i 2,1));
    }

    
// If the resulting sum is an even multiple of ten (but not zero),
    // the aba routing number is good.

    
if ($n != && $n 10 == 0)
    {
      return(
true); // found good aba
    
}
    else
    {
      return(
false);
    }

  }
  else
  {
    return(
false);
  }
}

?>


Usage Example


include("include/abavalidate.php");

if (!abavalidate($bankID))
{
  $errmsg[] = "The Bank I.D. Number is invalid.  It must be 9 digits (numbers only) and entered exactly as it appears on the bottom of your check.";
}


Rate This Script





Search



This Category All Categories