Mega Code Archive

 
Categories / Delphi / VCL
 

ABA Number Validator Components

Title: ABA Number Validator Components Question: Components to validate ABA Numbers. Answer: Introduction What is an ABA Number? ABA stands for American Banker's Association. It is used to identify the specific financial institution responsible for the payment. To find more about ABA, visit http://www.aba.com/Products/PS98_Routing.htm. How do we validate an ABA number? All the ABA numbers can be validated using an algorithm called CheckSum before us even submitting the transaction to the banks. CheckSum Algorithm The following is the implementation in Delphi: function IsValidABANumber(ABANumber: string): Boolean; var iLength, iCount, iCheckSum, iDigitWeight, iReminder, iLastDigit, iDigit : integer; begin Result := True; iLength := Length(Trim(ABANumber)); if (iLength 9) then begin Result := False; Exit; end; iDigitWeight := 0; iCheckSum := 0; for iCount := 1 to iLength - 1 do begin iDigit := StrToInt(ABANumber[iCount]); if (iCount = 1) or (iCount = 4) or (iCount = 7) then begin iDigitWeight := 3; end else if (iCount = 2) or (iCount = 5) or (iCount = 8) then begin iDigitWeight := 7; end else if (iCount = 3) or (iCount = 6) {or (iCount = 9)} then begin iDigitWeight := 1; end; iCheckSum := iCheckSum + (iDigit * iDigitWeight); end; iLastDigit := StrToInt(ABANumber[9]);; iReminder := iCheckSum mod 10; iCheckSum := 10 - iReminder; if (iCheckSum iLastDigit) then begin Result := False; end; end; While this algorithm is very easy to implement, I just thought of building some components in Delphi which will come in handy when we build any screens involving financial transactions. So I have built two components: One visual and one non-visual. The visual component - TABANumberEdit It is derived from TMaskEdit, implements the CheckSum algorithm to validate the ABA number. All you need to do is to drop this component on the form and the validation happens on exit of this component (when you tab out) automatically. As you can see from the Demo application, there are two properties that you can set: ValidateABANumber - Set to True by default WarningMessage - a Warning message will be displayed when you exit the component if the entered ABA number is invalid. You can enter your customized message here. By default, it is set to "Invalid ABA number entered! Please correct." Non-visual component - TABAValidator There are situations where you may need a non-visual component to do the same ABA number validation. This non-visual component does the ABA Number validation using the same CheckSum algorithm.. This component has two properties: ABANumber - This is to validate a single ABA Number ABANumbers - This is to validate a list of ABA Numbers This component has two methods: ValidateABANumber - Call this method after setting the ABANumber property; This method will return a boolean value; True means that the ABANumber is a valid number; False means invalid. FilterBadABANumbers - Call this method after setting up the ABANumbers property. This method will filter the Bad ABA Numbers from ABANumbers list and return a TStringList with the Bad ABA Numbers filtered. DEMO application I have put together a simple demo application, ABAValidatorDEMO.exe, to demonstrate the use of the visual component TABANumberEdit. As usual, Ill send the exe for this demo application and .bpl for the components to the Web Master as zipped. But when I sent it to webmaster, the mail got bounced back immediately. So, I uploaded the zip file onto www.4shared.com website and provided the link for you to download. I hope this works...