rsporteman / validator
provides a set of commonly needed validators
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/rsporteman/validator
Requires
- php: ^7.3 || ~8.0.0 || ~8.1.0
- laminas/laminas-validator: ^2.17
Requires (Dev)
- phpunit/php-code-coverage: ^9.2
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2025-12-28 06:09:37 UTC
README
rsporteman/validator
Introduction
Code for cpf and a cnpj validation, use like Laminas validators.
Installation using Composer
$ composer require rsporteman/validator
Example
<?php use rsporteman\Validator\Cpf; use rsporteman\Validator\Cnpj; $post['cpf'] = '313.734.531/68'; // it is valid $validatorCpf = new Cpf(); $isValidCpf = $validatorCpf->isValid($post['cpf']); //output: true $post['cnpj'] = '1364679'; //it is invalid $validatorCnpj = new Cnpj(); $isValidCnpj = $validatorCnpj->isValid($post['cnpj']); //output: false //Get Error messages //return array empty because cpf is valid $errorCnpjMsg = $validatorCpf->getMessages(); //output: [] //return array with errors messages because cnpj is invalid $errorCpfMsg = $validatorCnpj->getMessages(); var_dump($errorCpfMsg);// output: ['cnpjLength' => string 'The input contains an invalid amount of characters']
Ambience and Tests
#up docker container docker-compose up #enter on container docker exec -it rsporteman-validator bash #install dependencies composer install #run tests vendor/bin/phpunit #generate coverage, files will be generate inside .phpunit.cache composer test:coverage composer test:coverage-html