Validate ABN

In Australia businesses and companies can register for an Australian Business Number. They need this number in order to avoid the other companies and businesses they deal with having to withhold almost half of the payments to them as tax. Admittedly the business can apply the withheld amount against their tax liability at the end of the year but it is more useful for them to receive the money in the first place and pay any tax later. It is therefore useful for Australian businesses to apply for a business number if they are conducting a business regardless of how much business they will actually be doing.

The business numbers that are issued are all eleven digits long. The first two of the digits are calculated from the other nine digits such that it is easy to work out whether a given Australian Business Number is valid or not (being able to determine whether that ABN has actually been issued and belongs to that business is a completely different matter - here we are only considering whether the number could be a valid ABN).

We can easily create a JavaScript function where we can pass in the eleven digit ABN and return either true or false depending on whether the first two digits are the correct check digits for the rest of the number or not.

``````validABN = function(abn) {
"use strict";
var a, w, t;
w = [0,0,3,5,7,9,11,13,15,17,19];
a = abn.split('');
t = ''+a[0]+a[1];
w.forEach(function(v,i) {a[i] *= v;});
a = a.reduce(function(x,y) {return x+y;});
return (t == 99-(a%89));
}``````

We can now validate any Australian Business number simply by calling validABN and testing to confirm that the result returned is true.