Created
February 14, 2011 06:20
-
-
Save stuart/825553 to your computer and use it in GitHub Desktop.
Check a string to see if it is a valid 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
# Algorithm taken from ATO website. | |
def valid_abn?(abn) | |
WEIGHTS = [10,1,3,5,7,9,11,13,15,17,19] | |
tmpabn = abn.split("").map{|c| c.to_i} | |
tmpabn[0] = tmpabn[0] - 1 | |
checksum = (0..10).inject(0) do |sum, i| | |
sum + (tmpabn[i].to_i * WEIGHTS[i]) | |
end | |
return (checksum % 89) == 0 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment