Small library for validating Australian Business Numbers
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.gitignore
.travis.yml
CHANGELOG
Gemfile
MIT-LICENSE
README.markdown
Rakefile
abn.gemspec

README.markdown

A small library for validating Australian Business Numbers (ABN)

Installation

gem install abn

Usage

require 'abn'

ABN.new("12042168743").valid?
=> true

ABN.valid?("12042168743")
=> true

ABN.valid?("12042168744")
=> false

With ActiveRecord

Version 1.3 of this gem had an active record mixin for validating ABN fields in models. I removed it in version 2.0 to avoid complications of supporting active record 2.x and 3.x (and Datamapper, Mongoid, etc).

To validate an ABN field in your model add the ABN gem to your Gemfile and use the following pattern:

class Business < ActiveRecord::Base

validate :validate_abn

private

def validate_abn
  if self.abn.present && !ABN.valid?(self.abn)
    self.errors.add(:abn, "is not a valid ABN")
    false
  end
end

end

Further Reading