ABAValidator (npm, github) is just a JavaScript validation module that works both in Node.js on the server as well as in a client’s browser. It provides a simple way to validate routing numbers that conform to the American Banking Association Routing Number rules (wikipedia).
Installation
Installing ABAlidator is simple thanks to NPM. To install it, simply type the following command.
npm install ABAValidator
Using with Node.js
Once the package is installed using NPM, using the ABAValidator is as simple as importing in the module into your code.
var aba_validator = require("ABAValidator").ABAValidator; var is_valid = aba_valdiator.validate("123456789"); // returns false
Using with JavaScript
One goal I had when writing ABAValidator was to ensure that it can be used both client and server side. Being able to use it in both places ensure that you can write your validation code once and reuse it wherever.
UPDATE – 09 Aug. 2012: the module has been updated to utilize NPM more to make client-side installation easier than manually copying the script from node_modules or referencing directly from node_modules. Typing in the following command will prompt you for a client-side installation directory and then will automatically copy the script to your JavaScript source directory.
npm run-script ABAValidator client-install
To use the ABAValidator in object from a client’s browser, you simply have to reference the script using a typical <script>
tag and then use pretty much the same as above.
<script type="text/javascript" src="path/to/aba-validation.js"></script> <script type="text/javascript"> var aba_validator = window.ABAValidator; var is_valid = aba_valdiator.validate("123456789"); // returns false </script>
Global Objects Are Bad
I’m not a fan of adding objects into the global scope (or window
object) in my JavaScript code. Inside of the aba-validation.js class, I have allowed for a namespace
to be generated and used if the developer wishes to do such. If namespace
remains undefined
, the ABAValidator
object will be placed into the global scope.
To add a namespace for the client-side implementation of DateValidator, simply modify the first line of date-validator.js like the following:
window.MyNamespace = window.MyNamespace || {}; var namespace = window.MyNamespace;
Now, when it’s being consumed by the client side JavaScript, it’d be referenced in the following manner.
<script type="text/javascript"> var aba_validator = window.MyNamespace.ABAValidator; var is_valid = aba_valdiator.validate("123123123"); // returns true </script>
Summary
The ABAValidator module is still in its early stages and I’m always looking for feedback. If you have any suggestions or find any bugs, please submit them to the issue tracker over on github and I’ll see what I can do to get them updated. In addition, if you are looking for information on test routing numbers to use, please refer to this Stackoverflow question on the subject.