joulgs / php-utils
PHP validation and formatting tools
Installs: 22
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Language:HTML
Requires
- php: >=7.1
Requires (Dev)
- phpunit/phpunit: ^10.5
README
Installation
php-utils is available via composer. To install it, simply run the following command:
composer require joulgs/php-utils
Available Classes
FiscalDocuments
Allows you to validate a tax number and obtain its type (CPF, CNPJ or NIF).
Methods
Method | Description |
---|---|
getType | Returns the type of the tax number (CPF, CNPJ or NIS) |
isValid | Returns true if the tax number is valid |
isInvalid | Returns true if the tax number is invalid |
getMasked | Returns the tax number with a mask |
Example
<?php use JGS\Utils\FiscalDocuments; $doc_number = new FiscalDocuments('12345678901'); echo $doc_number->getType(); // CPF if($doc_number->isValid()) { echo "Valid Doc Number"; } if($doc_number->isInvalid()) { echo "Invalid Doc Number"; } echo $doc_number->getMasked(); // 123.456.789-01
Tools
A set of tools to help you with your daily tasks.
Methods
Method | Description |
---|---|
formatPhone | Formats a phone number |
mask | Applies a mask to a string |
*Other methods will be added soon.
Example
<?php use JGS\Utils\Tools; $phone = Tools::formatPhone('1234567890'); echo $phone; // (12) 3456-7890 $phone = Tools::formatPhone('12345678901'); echo $phone; // (12) 34567-8901 $phone = Tools::formatPhone('551234567890'); echo $phone; // +55 (12) 3456-7890 $phone = Tools::formatPhone('5512345678901'); echo $phone; // +55 (12) 34567-8901 $masked = Tools::mask('12345678901', '###.###.###-##'); echo $masked; // 123.456.789-01 $masked = Tools::mask('1234567890', '##-##-##-##'); echo $masked; // 12-34-56-78