public
Description: Small library for validating Australian Business Numbers
Homepage:
Clone URL: git://github.com/yob/abn.git
abn / README.rdoc
100644 41 lines (23 sloc) 0.828 kb

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