public
Description: Small library for validating Australian Business Numbers
Homepage:
Clone URL: git://github.com/yob/abn.git
abn /
name age message
file CHANGELOG Loading commit data...
file MIT-LICENSE Mon Jul 28 01:24:51 -0700 2008 initial commit [yob]
file README.rdoc
file Rakefile Tue Aug 12 18:44:46 -0700 2008 update a few files to reference the fact this g... [yob]
file TODO Mon Aug 11 23:26:05 -0700 2008 added TODO for support for business.gov.au API [bjeanes]
file abn.gemspec
directory lib/
directory spec/
README.rdoc

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

The gem includes a simple ActiveRecord method to validate your model attributes and ensure they’re a valid ABN.

Start by loading the gem in your app. In Rails 2.1 or higher, the best place to do this is in config/environment.rb

    config.gem "abn", :version => "1.3.0"

Then just add the follow line to your model:

    validates_abn_correctness_of :abn

If you want to allow empty values, then the standard option for that works:

    validates_abn_correctness_of :abn, :allow_nil => true

Further Reading