No commit activity in last 3 years
No release in over 3 years
Adds validation methods considering different country zip code formats. Currently, we can validate 130 countries.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.11
~> 10.0
~> 3.0
~> 3.5

Runtime

 Project Readme

ValidateZipcode

Gem Version Build Status Coverage Status

Adds ZipCode / PostalCode validation support to Rails (ActiveModel) and test it in a simple way.

Any other country's postal code that not on the list of country identification will validate without errors.

Installation

Add this line to your application's Gemfile:

gem 'validate_zipcode'

And then execute:

$ bundle

Or install it yourself as:

$ gem install validate_zipcode

Usage

Just use as any other validator passing the country:

ValidateZipcode expects the model has an attribute called country to contain the country identification.

This Gem use as country identification the codes supplied by the ISO 3166-2 (International Organization for Standardization).

class Address < ActiveRecord::Base
  validates :zipcode, zipcode: {country: "US"}
end

Error Message

If you need to localize the error message, just add this to your I18n locale file:

errors:
  messages:
    this_zip_code_is_invalid: "This zip code is invalid"

You can provide your own message using :message option.

validates :zipcode, zipcode: {country: "US", message: "new error message"}

Mantainers

RamonHossein

Contributors

To see the generous people who have contributed code, take a look at the contributors list.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

The gem is available as open source under the terms of the MIT License.