PHP code example of devralint / cuit-cuil-validator
1. Go to this page and download the library: Download devralint/cuit-cuil-validator library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Devralint\Cuit\Cuit;
use Devralint\Cuit\Exception\InvalidCuitException;
// Construcción estricta: lanza InvalidCuitException si inválido
$cuit = Cuit::fromString('20-12345678-6');
echo $cuit->prefix; // "20"
echo $cuit->body; // "12345678"
echo $cuit->checkDigit; // 6
echo $cuit->formatted(); // "20-12345678-6"
echo (string) $cuit; // "20-12345678-6"
$cuit->isFisica(); // true
$cuit->isJuridica(); // false
// Construcción tolerante: devuelve null si inválido
$cuit = Cuit::tryFrom('invalido'); // null
use Devralint\Cuit\PersonaType;
$cuit->type; // PersonaType::Fisica | PersonaType::Juridica | PersonaType::Otro
// En un Form Request
use Devralint\Cuit\Validator as CuitValidator;
$request->validate([
'cuit' => ['IL válido.");
}
}],
]);
use Devralint\Cuit\Validator as CuitValidator;
use yii\validators\Validator;
class CuitValidator extends Validator
{
public function validateValue($value): ?array
{
return CuitValidator::isValid((string) $value)
? null
: [$this->message ?? 'CUIT/CUIL inválido.', []];
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.