{"id":32708043,"url":"https://github.com/lacussolutions/br-utils-php_cnpj-val","last_synced_at":"2026-01-20T17:28:04.941Z","repository":{"id":313142084,"uuid":"1049981798","full_name":"LacusSolutions/br-utils-php_cnpj-val","owner":"LacusSolutions","description":"Utility function to validate CNPJ (Brazilian employer ID).","archived":false,"fork":false,"pushed_at":"2025-10-17T23:30:40.000Z","size":27,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-26T19:44:37.050Z","etag":null,"topics":["br","cnpj","composer","helpers","packagist","php","utils","validator"],"latest_commit_sha":null,"homepage":"https://github.com/LacusSolutions/br-utils-php","language":"PHP","has_issues":false,"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/LacusSolutions.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-03T19:21:23.000Z","updated_at":"2025-10-17T23:30:44.000Z","dependencies_parsed_at":"2025-09-04T06:49:06.364Z","dependency_job_id":"557624a8-362d-4749-b840-358fef1009da","html_url":"https://github.com/LacusSolutions/br-utils-php_cnpj-val","commit_stats":null,"previous_names":["lacussolutions/br-utils-php_cnpj-val"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/LacusSolutions/br-utils-php_cnpj-val","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LacusSolutions%2Fbr-utils-php_cnpj-val","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LacusSolutions%2Fbr-utils-php_cnpj-val/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LacusSolutions%2Fbr-utils-php_cnpj-val/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LacusSolutions%2Fbr-utils-php_cnpj-val/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LacusSolutions","download_url":"https://codeload.github.com/LacusSolutions/br-utils-php_cnpj-val/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LacusSolutions%2Fbr-utils-php_cnpj-val/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":282234691,"owners_count":26636392,"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","status":"online","status_checked_at":"2025-11-02T02:00:06.609Z","response_time":64,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["br","cnpj","composer","helpers","packagist","php","utils","validator"],"created_at":"2025-11-02T03:01:36.887Z","updated_at":"2026-01-20T17:28:04.929Z","avatar_url":"https://github.com/LacusSolutions.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"![cnpj-val for PHP](https://br-utils.vercel.app/img/cover_cnpj-val.jpg)\n\n[![Packagist Version](https://img.shields.io/packagist/v/lacus/cnpj-val)](https://packagist.org/packages/lacus/cnpj-val)\n[![Packagist Downloads](https://img.shields.io/packagist/dm/lacus/cnpj-val)](https://packagist.org/packages/lacus/cnpj-val)\n[![PHP Version](https://img.shields.io/packagist/php-v/lacus/cnpj-val)](https://www.php.net/)\n[![Test Status](https://img.shields.io/github/actions/workflow/status/LacusSolutions/br-utils-php/ci.yml?label=ci/cd)](https://github.com/LacusSolutions/br-utils-php/actions)\n[![Last Update Date](https://img.shields.io/github/last-commit/LacusSolutions/br-utils-php)](https://github.com/LacusSolutions/br-utils-php)\n[![Project License](https://img.shields.io/github/license/LacusSolutions/br-utils-php)](https://github.com/LacusSolutions/br-utils-php/blob/main/LICENSE)\n\nUtility function/class to validate CNPJ (Brazilian employer ID).\n\n## PHP Support\n\n| ![PHP 8.1](https://img.shields.io/badge/PHP-8.1-777BB4?logo=php\u0026logoColor=white) | ![PHP 8.2](https://img.shields.io/badge/PHP-8.2-777BB4?logo=php\u0026logoColor=white) | ![PHP 8.3](https://img.shields.io/badge/PHP-8.3-777BB4?logo=php\u0026logoColor=white) | ![PHP 8.4](https://img.shields.io/badge/PHP-8.4-777BB4?logo=php\u0026logoColor=white) |\n|--- | --- | --- | --- |\n| Passing ✔ | Passing ✔ | Passing ✔ | Passing ✔ |\n\n## Installation\n\n```bash\n# using Composer\n$ composer require lacus/cnpj-val\n```\n\n## Import\n\n```php\n\u003c?php\n// Using class-based resource\nuse Lacus\\CnpjVal\\CnpjValidator;\n\n// Or using function-based one\nuse function Lacus\\CnpjVal\\cnpj_val;\n```\n\n## Usage\n\n### Object-Oriented Usage\n\n```php\n$validator = new CnpjValidator();\n$cnpj = '98765432000198';\n\necho $validator-\u003eisValid($cnpj) ? 'Valid' : 'Invalid';  // returns 'Valid'\n\n$cnpj = '98.765.432/0001-98';\necho $validator-\u003eisValid($cnpj) ? 'Valid' : 'Invalid';  // returns 'Valid'\n\n$cnpj = '98765432000199';\necho $validator-\u003eisValid($cnpj) ? 'Valid' : 'Invalid';  // returns 'Invalid'\n```\n\n### Imperative programming\n\nThe helper function `cnpj_val()` is just a functional abstraction. Internally it creates an instance of `CnpjValidator` and calls the `isValid()` method right away.\n\n```php\n$cnpj = '98765432000198';\n\necho cnpj_val($cnpj) ? 'Valid' : 'Invalid';      // returns 'Valid'\n\necho cnpj_val('98.765.432/0001-98') ? 'Valid' : 'Invalid';  // returns 'Valid'\n\necho cnpj_val('98765432000199') ? 'Valid' : 'Invalid';      // returns 'Invalid'\n```\n\n### Validation Examples\n\n```php\n// Valid CNPJ numbers\ncnpj_val('98765432000198')      // returns true\ncnpj_val('98.765.432/0001-98')  // returns true\ncnpj_val('03603568000195')      // returns true\n\n// Invalid CNPJ numbers\ncnpj_val('98765432000199')      // returns false\ncnpj_val('12345678901234')      // returns false\ncnpj_val('00000000000000')      // returns false\ncnpj_val('11111111111111')      // returns false\ncnpj_val('123')                 // returns false (too short)\ncnpj_val('')                    // returns false (empty)\n```\n\n## Features\n\n- ✅ **Format Agnostic**: Accepts CNPJ with or without formatting (dots, slashes, dashes)\n- ✅ **Strict Validation**: Validates both check digits according to Brazilian CNPJ algorithm\n- ✅ **Type Safety**: Built with PHP 8.1+ strict types\n- ✅ **Lightweight**: Minimal dependencies, only requires `lacus/cnpj-gen` for check digit calculation\n- ✅ **Dual API**: Both object-oriented and functional programming styles supported\n\n## API Reference\n\n### CnpjValidator Class\n\n#### `isValid(string $cnpjString): bool`\n\nValidates a CNPJ string and returns `true` if valid, `false` otherwise.\n\n**Parameters:**\n- `$cnpjString` (string): The CNPJ to validate (with or without formatting)\n\n**Returns:**\n- `bool`: `true` if the CNPJ is valid, `false` otherwise\n\n### cnpj_val() Function\n\n#### `cnpj_val(string $cnpjString): bool`\n\nFunctional wrapper around `CnpjValidator::isValid()`.\n\n**Parameters:**\n- `$cnpjString` (string): The CNPJ to validate (with or without formatting)\n\n**Returns:**\n- `bool`: `true` if the CNPJ is valid, `false` otherwise\n\n## Validation Algorithm\n\nThe package validates CNPJ using the official Brazilian algorithm:\n\n1. **Length Check**: Ensures the CNPJ has exactly 14 digits\n2. **First Check Digit**: Calculates and validates the 13th digit\n3. **Second Check Digit**: Calculates and validates the 14th digit\n4. **Format Tolerance**: Automatically strips non-numeric characters before validation\n\n## Error Handling\n\nThe validator is designed to be forgiving with input format but strict with validation:\n\n- Invalid formats (too short, too long) return `false`\n- Invalid check digits return `false`\n- Empty strings return `false`\n- Non-numeric strings (after stripping formatting) return `false`\n\n## Dependencies\n\n- **PHP**: \u003e= 8.1\n- **lacus/cnpj-gen**: ^1.0 (for check digit calculation)\n\n## Contribution \u0026 Support\n\nWe welcome contributions! Please see our [Contributing Guidelines](https://github.com/LacusSolutions/br-utils-php/blob/main/CONTRIBUTING.md) for details. But if you find this project helpful, please consider:\n\n- ⭐ Starring the repository\n- 🤝 Contributing to the codebase\n- 💡 [Suggesting new features](https://github.com/LacusSolutions/br-utils-php/issues)\n- 🐛 [Reporting bugs](https://github.com/LacusSolutions/br-utils-php/issues)\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](https://github.com/LacusSolutions/br-utils-php/blob/main/LICENSE) file for details.\n\n## Changelog\n\nSee [CHANGELOG](https://github.com/LacusSolutions/br-utils-php/blob/main/packages/cnpj-val/CHANGELOG.md) for a list of changes and version history.\n\n---\n\nMade with ❤️ by [Lacus Solutions](https://github.com/LacusSolutions)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flacussolutions%2Fbr-utils-php_cnpj-val","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flacussolutions%2Fbr-utils-php_cnpj-val","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flacussolutions%2Fbr-utils-php_cnpj-val/lists"}