Download the PHP package lacus/cpf-val without Composer
On this page you can find all versions of the php package lacus/cpf-val. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lacus/cpf-val
More information about lacus/cpf-val
Files in lacus/cpf-val
Informations about the package cpf-val

Utility function/class to validate CPF (Brazilian personal ID).
PHP Support
| Passing ✔ | Passing ✔ | Passing ✔ | Passing ✔ |
Installation
Import
Usage
Object-Oriented Usage
Imperative programming
The helper function cpf_val() is just a functional abstraction. Internally it creates an instance of CpfValidator and calls the isValid() method right away.
Validation Examples
Features
- ✅ Format Agnostic: Accepts CPF with or without formatting (dots, dashes)
- ✅ Strict Validation: Validates both check digits according to Brazilian CPF algorithm
- ✅ Type Safety: Built with PHP 8.1+ strict types
- ✅ Lightweight: Minimal dependencies, only requires
lacus/cpf-genfor check digit calculation - ✅ Dual API: Both object-oriented and functional programming styles supported
API Reference
CpfValidator Class
isValid(string $cpfString): bool
Validates a CPF string and returns true if valid, false otherwise.
Parameters:
$cpfString(string): The CPF to validate (with or without formatting)
Returns:
bool:trueif the CPF is valid,falseotherwise
cpf_val() Function
cpf_val(string $cpfString): bool
Functional wrapper around CpfValidator::isValid().
Parameters:
$cpfString(string): The CPF to validate (with or without formatting)
Returns:
bool:trueif the CPF is valid,falseotherwise
Validation Algorithm
The package validates CPF using the official Brazilian algorithm:
- Length Check: Ensures the CPF has exactly 11 digits
- First Check Digit: Calculates and validates the 10th digit
- Second Check Digit: Calculates and validates the 11th digit
- Format Tolerance: Automatically strips non-numeric characters before validation
Error Handling
The validator is designed to be forgiving with input format but strict with validation:
- Invalid formats (too short, too long) return
false - Invalid check digits return
false - Empty strings return
false - Non-numeric strings (after stripping formatting) return
false
Dependencies
- PHP: >= 8.1
- lacus/cpf-gen: ^1.0 (for check digit calculation)
Contribution & Support
We welcome contributions! Please see our Contributing Guidelines for details. But if you find this project helpful, please consider:
- ⭐ Starring the repository
- 🤝 Contributing to the codebase
- 💡 Suggesting new features
- 🐛 Reporting bugs
License
This project is licensed under the MIT License - see the LICENSE file for details.
Changelog
See CHANGELOG for a list of changes and version history.
Made with ❤️ by Lacus Solutions