Download the PHP package phillarmonic/cpf-cnpj without Composer
On this page you can find all versions of the php package phillarmonic/cpf-cnpj. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download phillarmonic/cpf-cnpj
More information about phillarmonic/cpf-cnpj
Files in phillarmonic/cpf-cnpj
Package cpf-cnpj
Short Description A PHP library for validating and formatting CPF and CNPJ numbers.
License MIT
Informations about the package cpf-cnpj
phillarmonic/cpf-cnpj
A PHP library for validating and formatting CPF and CNPJ numbers from Brazil.
Installation
You can install this library using Composer. Run the following command in your project directory:
Usage
Validating CPF Numbers
To validate a CPF number:
Formatting CPF Numbers
To format a valid CPF number:
Validating CNPJ Numbers
To validate a CNPJ number:
Formatting CNPJ Numbers
To format a valid CNPJ number:
Important Notes
- The library automatically removes any non-digit characters from the input, so you can pass formatted or unformatted numbers.
- The
isValid()
method checks for:- Correct length (11 digits for CPF, 14 digits for CNPJ)
- Not in the blacklist of known invalid numbers
- Validity of check digits
- The
format()
method returnsfalse
if the number is invalid.
Error Handling
The library doesn't throw exceptions. Instead, it returns false
or fails silently in case of invalid input. Always check the return value of isValid()
before using the number, and check if format()
returns false
before using the formatted result.
Contributing
If you'd like to contribute to this project, please submit a pull request on the GitHub repository.
License
This library is open-sourced software licensed under the MIT license.