rails validation plugin. validates postal and zip codes.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.



Strict validation module for postal and zip codes.

= General usage

== Installation

You can install the plugin the traditional way. Go to your application root
and do:

  script/plugin install git://github.com/paulschreiber/validates_as_postal_code.git

== Validate your model attributes


There are three ways to specify the country:
 (1) Pass the country name in as a string parameter (:country => "CA")
 class Person < ActiveRecord::Base
   validates_as_postal_code :postal_code, :country => "CA", :allow_blank => true

 (2) Create an attribute (country field) named foo in your object, and pass in a reference to foo:
 class Person < ActiveRecord::Base
   validates_as_postal_code :postal_code, :country => :foo

 (3) Create an attribute named country it in your object, i.e. Person#country
     i.e. country is the default name for your country field, and the validator tries that automatically

 class Person < ActiveRecord::Base
   validates_as_postal_code :postal_code

The :set parameter tells the validator to reformat the postal_code number (change punctuation and spacing) in to a standard format.

Supported countries are Canada (CA), the United States (US), Australia (AU), New Zealand (NZ). :set only works for Canada and the US; it's ignored for other countries.

= License

Copyright (c) 2010 Paul Schreiber, released under the MIT license