-
-
Save teebu/379573309ad39e0699dd09ccf9585906 to your computer and use it in GitHub Desktop.
Validate Australian Business Number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Checks ABN for validity using the published ABN checksum algorithm. | |
* @author Guy Carpenter | |
* @license http://www.clearwater.com.au/code None | |
* @param {String|Number} value abn to validate | |
* @return {Boolean} Is ABN Valid | |
*/ | |
function validateABN (value) { | |
var weights = [10, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19], | |
abn = value.replace(/[^\d]/g, ''), | |
result = false; | |
// check length is 11 digits | |
if (abn.length === 11) { | |
// apply ato check method | |
var sum = 0, | |
weight; | |
for (var index = 0; index <= weights.length - 1; index++) { | |
weight = weights[index]; | |
digit = abn[index] - (index ? 0 : 1); | |
sum += weight * digit; | |
} | |
result = sum % 89 === 0; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment