PHP code example of tavo1987 / ec-validador-cedula-ruc
1. Go to this page and download the library: Download tavo1987/ec-validador-cedula-ruc 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/ */
tavo1987 / ec-validador-cedula-ruc example snippets
use Tavo\ValidadorEc;
$validator = new ValidadorEc();
// Validate any document type
if (ValidadorEc::isValid('0926687856')) {
echo 'Valid document';
}
// Validate specific document types
ValidadorEc::isValidCedula('0926687856'); // true
ValidadorEc::isValidNaturalPersonRuc('0926687856001'); // true
ValidadorEc::isValidPrivateCompanyRuc('0992397535001'); // true
ValidadorEc::isValidPublicCompanyRuc('1760001550001'); // true
// Cedula (10 digits)
if ($validator->validate('0926687856')) {
echo 'Valid: ' . $validator->getDocumentType(); // "cedula"
}
// Natural Person RUC (13 digits, third digit 0-5)
if ($validator->validate('0926687856001')) {
echo 'Valid: ' . $validator->getDocumentType(); // "ruc_natural"
}
// Public Company RUC (13 digits, third digit 6)
if ($validator->validate('1760001550001')) {
echo 'Valid: ' . $validator->getDocumentType(); // "ruc_public"
}
// Private Company RUC (13 digits, third digit 9)
if ($validator->validate('0992397535001')) {
echo 'Valid: ' . $validator->getDocumentType(); // "ruc_private"
}
// Validate Cedula
if ($validator->validateCedula('0926687856')) {
echo 'Valid Cedula';
} else {
echo 'Error: ' . $validator->getError();
}
// Validate Natural Person RUC
if ($validator->validateNaturalPersonRuc('0926687856001')) {
echo 'Valid RUC';
}
// Validate Private Company RUC
if ($validator->validatePrivateCompanyRuc('0992397535001')) {
echo 'Valid RUC';
}
// Validate Public Company RUC
if ($validator->validatePublicCompanyRuc('1760001550001')) {
echo 'Valid RUC';
}
$cedula = $validator->extractCedulaFromRuc('0926687856001');
// Returns: '0926687856'
// Returns null for Private/Public Company RUC (no cedula)
$result = $validator->extractCedulaFromRuc('0992397535001');
// Returns: null
// Returns null for invalid RUC
$result = $validator->extractCedulaFromRuc('invalid');
// Returns: null