{"id":13483695,"url":"https://github.com/dgilperez/validates_zipcode","last_synced_at":"2025-05-16T10:06:34.216Z","repository":{"id":21207133,"uuid":"24519972","full_name":"dgilperez/validates_zipcode","owner":"dgilperez","description":"Postal code / zipcode validation for Rails, supporting 233 country codes","archived":false,"fork":false,"pushed_at":"2024-09-10T16:25:59.000Z","size":202,"stargazers_count":140,"open_issues_count":1,"forks_count":51,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-05-06T20:19:05.134Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dgilperez.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-09-27T00:58:56.000Z","updated_at":"2025-03-26T22:41:14.000Z","dependencies_parsed_at":"2024-09-10T18:04:49.461Z","dependency_job_id":null,"html_url":"https://github.com/dgilperez/validates_zipcode","commit_stats":{"total_commits":173,"total_committers":33,"mean_commits":5.242424242424242,"dds":"0.34104046242774566","last_synced_commit":"a5be66faafa5eb888b2715c0b1b4274e8f4eacc9"},"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgilperez%2Fvalidates_zipcode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgilperez%2Fvalidates_zipcode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgilperez%2Fvalidates_zipcode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgilperez%2Fvalidates_zipcode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dgilperez","download_url":"https://codeload.github.com/dgilperez/validates_zipcode/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254509476,"owners_count":22082891,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T17:01:14.260Z","updated_at":"2025-05-16T10:06:34.196Z","avatar_url":"https://github.com/dgilperez.png","language":"Ruby","readme":"# ValidatesZipcode [![Build Status](https://secure.travis-ci.org/dgilperez/validates_zipcode.png)](https://travis-ci.org/dgilperez/validates_zipcode) [![Code Climate](https://codeclimate.com/github/dgilperez/validates_zipcode/badges/gpa.svg)](https://codeclimate.com/github/dgilperez/validates_zipcode) [![Gem Version](https://badge.fury.io/rb/validates_zipcode.svg)](http://badge.fury.io/rb/validates_zipcode) [![security](https://hakiri.io/github/dgilperez/validates_zipcode/master.svg)](https://hakiri.io/github/dgilperez/validates_zipcode/master)\n\nAdds zipcode / postal code validation support to Rails (ActiveModel), considering postal code formats for mostly every country.\n\n``ValidatesZipcode`` currently support **233 country codes**. Regex data taken from several sources, being the main source the [CLDR](http://unicode.org/cldr/trac/browser/tags/release-27-d05/common/supplemental/postalCodeData.xml) database (release 27, around 159). Any other country's postal code will validate without errors.\n\n``ValidatesZipcode`` supports Rails \u003e= 4.2 and Ruby \u003e= 2.4. This gem could work in Rails 3.2 and Ruby 1.9.3 as well, yet unsupported; try v0.2 series if having trouble with later versions. Truffleruby is also tested, but no reports of working in production apps for now.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n```ruby\ngem 'validates_zipcode'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install validates_zipcode\n\n## Usage\n\n### With ActiveModel::Validations\n\n```ruby\nvalidates_zipcode :zipcode\n\nvalidates :zipcode, zipcode: true\n```\n\n``ValidatesZipcode`` expects the model to have an attribute called ``country_alpha2`` to contain the country code.\nYou can provide your own country_code using ``:country_code`` option, or specify which attribute contains this information\nusing ``:country_code_attribute`` option.\n\n```ruby\nvalidates :zipcode, zipcode: { country_code: :es }\n\nvalidates :zipcode, zipcode: { country_code_attribute: :my_country_code_column }\n```\n\n#### Error Messaging\n\nIf you need to localize the error message, just add this to your I18n locale file:\n\n```yaml\nerrors:\n  messages:\n    invalid_zipcode: Your zipcode error message.\n```\n\nYou can override this on a per-model basis by passing in a ``:message`` key with the validation:\n\n```ruby\nvalidates :zipcode, zipcode: { message: 'Your per-model zipcode error message.' }\n```\n\n### Without ActiveModel::Validations\n\n```ruby\nValidatesZipcode.valid?('93108', 'ES')\n# =\u003e true\n```\n\n### Formatting\n\nThis gem can also be used for formatting zipcodes according to country specific rules.\n\n```ruby\nValidatesZipcode.format('Sw1A 2aA', 'UK')\n# =\u003e 'SW1A 2AA'\n```\n\nIf the zipcode is not valid an exception is raised.\n\n```ruby\nValidatesZipcode.format('Sw1A 2aA', 'FR')\n# =\u003e raises ValidatesZipcode::InvalidZipcodeError\n```\n\nAt the moment not every country is supported. See [lib/validates_zipcode/formatter.rb](lib/validates_zipcode/formatter.rb) to find all available countries.\n\n### Test data\n\nIn order to generate test data, we suggest using the [regexp-examples gem](https://github.com/tom-lord/regexp-examples)\nThis dependency will allow you to create examples as follows:\n\n```ruby\nrequire \"regexp-examples\"\n\nValidatesZipcode::CldrRegexpCollection::ZIPCODES_REGEX[:ES].examples\n\n# =\u003e [\"00000\", \"00001\", \"00002\", \"00003\", ..., \"44443\", \"44444\"]\n\nValidatesZipcode::CldrRegexpCollection::ZIPCODES_REGEX[:ES].random_example\n\n# =\u003e \"27072\"\n```\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\nAlso, you should read and follow our [Code of Conduct](https://github.com/dgilperez/validates_zipcode/blob/master/CODE_OF_CONDUCT.md).\n\n## Contributors\n\nTo see the generous people who have contributed code, take a look at the [contributors list](http://github.com/dgilperez/validates_zipcode/contributors).\n\n## Maintainers\n\n* [David Gil](http://github.com/dgilperez)\n\n## License\n\nCopyright (c) 2014 David Gil Pérez, released under the MIT license\n","funding_links":[],"categories":["Ruby","Country Data"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdgilperez%2Fvalidates_zipcode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdgilperez%2Fvalidates_zipcode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdgilperez%2Fvalidates_zipcode/lists"}