Home > validates_as_postal_code

validates_as_postal_code

Validates_as_postal_code is a project mainly written in Ruby, it's free.

rails validation plugin. validates postal and zip codes.

validates_as_postal_code

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

Example:

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 end

(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 end

(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 end

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