{"id":20785607,"url":"https://github.com/barbieswimcrew/zip-code-validator","last_synced_at":"2025-04-08T11:15:43.500Z","repository":{"id":2443878,"uuid":"46554309","full_name":"barbieswimcrew/zip-code-validator","owner":"barbieswimcrew","description":"Constraint Class for international Zipcode Validation","archived":false,"fork":false,"pushed_at":"2024-12-09T09:33:22.000Z","size":82,"stargazers_count":75,"open_issues_count":0,"forks_count":18,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-01T10:11:36.797Z","etag":null,"topics":["constraints","country","international-zipcode-validation","postal-code","postal-codes","postalcode","validation","zipcode","zipcodes"],"latest_commit_sha":null,"homepage":null,"language":"PHP","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/barbieswimcrew.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2015-11-20T10:03:53.000Z","updated_at":"2025-03-29T16:15:05.000Z","dependencies_parsed_at":"2024-06-19T01:49:50.042Z","dependency_job_id":"6b655957-8455-46e8-bf3a-3e11ec22d8a5","html_url":"https://github.com/barbieswimcrew/zip-code-validator","commit_stats":{"total_commits":60,"total_committers":25,"mean_commits":2.4,"dds":0.6333333333333333,"last_synced_commit":"c060097cb0ca54addd6372da0c419bab22ae1d34"},"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barbieswimcrew%2Fzip-code-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barbieswimcrew%2Fzip-code-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barbieswimcrew%2Fzip-code-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barbieswimcrew%2Fzip-code-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/barbieswimcrew","download_url":"https://codeload.github.com/barbieswimcrew/zip-code-validator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247829512,"owners_count":21002997,"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":["constraints","country","international-zipcode-validation","postal-code","postal-codes","postalcode","validation","zipcode","zipcodes"],"created_at":"2024-11-17T14:46:34.382Z","updated_at":"2025-04-08T11:15:43.469Z","avatar_url":"https://github.com/barbieswimcrew.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Constraint Class for international Zipcode Validation\n\n[![Build Status](https://github.com/barbieswimcrew/zip-code-validator/actions/workflows/ci.yaml/badge.svg)](https://github.com/barbieswimcrew/zip-code-validator/actions/workflows/ci.yaml)\n[![Downloads](https://img.shields.io/packagist/dt/barbieswimcrew/zip-code-validator.svg?style=flat-square)](https://packagist.org/packages/barbieswimcrew/zip-code-validator)\n[![Latest stable version](https://img.shields.io/packagist/v/barbieswimcrew/zip-code-validator.svg?style=flat-square)](https://packagist.org/packages/barbieswimcrew/zip-code-validator)\n[![PHP from Packagist](https://img.shields.io/packagist/php-v/barbieswimcrew/zip-code-validator.svg?style=flat-square)](./composer.json)\n[![GitHub stars](https://img.shields.io/github/stars/barbieswimcrew/zip-code-validator.svg?style=flat-square\u0026label=Stars\u0026style=flat-square)](https://github.com/barbieswimcrew/zip-code-validator/stargazers)\n[![MIT licensed](https://img.shields.io/github/license/barbieswimcrew/zip-code-validator.svg?style=flat-square)](https://github.com/barbieswimcrew/zip-code-validator/blob/master/LICENSE)\n\n## Installation\nThis package uses Composer, please checkout the [composer website](https://getcomposer.org) for more information.\n\nThe following command will install `zip-code-validator` into your project. It will also add a new entry in your `composer.json` and update the `composer.lock` as well.\n\n```bash\n$ composer require barbieswimcrew/zip-code-validator\n```\n\n\u003e This package follows the PSR-4 convention names for its classes, which means you can easily integrate `zip-code-validator` classes loading in your own autoloader.\n\n## What now?\nFor validating a zip code you need to instantiate a new ZipCode class provided by this package to set it as a constraint to your form field, for example:\n\n```php\n\u003c?php\n//...\n$form = $this-\u003ecreateFormBuilder($address)\n    -\u003eadd('zipcode', TextType::class, [\n        'constraints' =\u003e [\n            new ZipCodeValidator\\Constraints\\ZipCode([\n                'iso' =\u003e 'DE'\n            ])\n        ]\n    ])\n    -\u003eadd('save', SubmitType::class, ['label' =\u003e 'Create Task'])\n    -\u003egetForm();\n```\n\nAnother way would be to use the constraint as an annotation of a class property, for example:\n```php\n\u003c?php\n\nuse ZipCodeValidator\\Constraints\\ZipCode;\n\nclass Address\n{\n    /**\n     * @ZipCode(iso=\"DE\")\n     */\n    protected $zipCode;\n}\n```\n\nYou can also use it as a PHP8 Attribute, with parameters passed as an array of options, for example:\n```php\n\u003c?php\n\nuse ZipCodeValidator\\Constraints\\ZipCode;\n\nclass Address\n{\n    #[ZipCode(['iso'=\u003e'DE'])\n    protected $zipCode;\n}\n```\n\n\u003e  Please consider to inject a valid ISO 3166 2-letter country code (e.g. DE, US, FR)!\n\n\u003e  NOTE: This library validates against known zip code regex patterns and does not validate the existence of a zipcode.\n\n### Use a getter to inject the country code dynamically\n\nIf you have a form, in which the user can select a country, you may want to validate the zip code dynamically.\nIn this case you can use the `getter` option instead:\n\n```php\n\u003c?php\n\nuse ZipCodeValidator\\Constraints\\ZipCode;\n\nclass Address\n{\n    /**\n     * @ZipCode(getter=\"getCountry\")\n     */\n    protected $zipCode;\n\n    protected $country;\n\n    public function getCountry()\n    {\n        return $this-\u003ecountry;\n    }\n}\n```\n\nTo disable that the validator throws an exception, when the zip code pattern is not available for a country,\nyou can set the `strict` option to `FALSE`.\n\n```php\n/**\n * @ZipCode(getter=\"getCountry\", strict=false)\n */\nprotected $zipCode;\n```\n\nThe validator will not validate empty strings and null values. To disallow them use the Symfony stock `NotNull` or `NotBlank` constraint in addition to `ZipCode`.\n\n```php\n/**\n * @ZipCode(getter=\"getCountry\")\n * @NotBlank \n */\nprotected $zipCode;\n```\n\n### Case insensitive zip code matching\nIn case you want to match the zip code in a case insensitive way you have to pass a `caseSensitiveCheck` parameter with `false` value via the constructor:\n```php\n$constraint = new ZipCode([\n    'iso' =\u003e 'GB', \n    'caseSensitiveCheck' =\u003e false\n]);\n\n```\nBy the default the library is using case sensitive zip code matching.\n\n## Copying / License\nThis repository is distributed under the MIT License (MIT). You can find the whole license text in the [LICENSE](LICENSE) file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbarbieswimcrew%2Fzip-code-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbarbieswimcrew%2Fzip-code-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbarbieswimcrew%2Fzip-code-validator/lists"}