Skip to content

Instantly share code, notes, and snippets.

@stuart
Created February 14, 2011 06:20
Show Gist options
  • Save stuart/825553 to your computer and use it in GitHub Desktop.
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
# 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