ABN - Australian Business Numbers

I knew they had to be numeric and 11 digits. Then i found this:
http://www.ato.gov.au/businesses/content.asp?doc=/content/13187.htm&pc=001/003/021/002/001&mnu=610&mfp=001/003&st=&cy=1

Which explains quite nicely how to validate a number. So I thought I
would share this:

        function abnValidate(value, element){
            if (value.length != 11 || isNaN(parseInt(value)))
                return false;

            var weighting =
[10,1,3,5,7,9,11,13,15,17,19];
            var tally = (parseInt(value[0]) - 1) * weighting[0];
            for (var i = 1; i < value.length; i++){
                tally += (parseInt(value[i]) * weighting[i]);
            }

            return (tally % 89) == 0;
        }

        jQuery.validator.addMethod(
            'abnValidate',
            abnValidate, 'This ABN is not valid'
        );

Reply via email to