Created
February 6, 2023 02:31
-
-
Save Hillsie/0aaa529e005693c69948f42867fe487a to your computer and use it in GitHub Desktop.
Validate ABN - (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
function validateABN(abn: string): boolean { | |
/* | |
@name: validateABN | |
@param {string} abn | |
@returns {boolean} | |
@link https://abr.business.gov.au/Help/AbnFormat | |
*/ | |
const weightingFactors = [10, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19] | |
const cleanedABN = abn.replace(/\s/g, '') | |
if (cleanedABN.length !== 11) { | |
return false | |
} | |
let sum = 0 | |
for (let i = 0; i < 11; i++) { | |
sum += (parseInt(cleanedABN[i]) - (i === 0 ? 1 : 0)) * weightingFactors[i] | |
} | |
return sum % 89 === 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment