PHPackages                             tavo1987/ec-validador-cedula-ruc - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. tavo1987/ec-validador-cedula-ruc

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

tavo1987/ec-validador-cedula-ruc
================================

Ecuador ID (Cedula) and RUC Validator

v2.0.1(4mo ago)1642.9k↓36%125MITPHPPHP ^8.2CI passing

Since May 30Pushed 4mo ago3 watchersCompare

[ Source](https://github.com/tavo1987/ec-validador-cedula-ruc)[ Packagist](https://packagist.org/packages/tavo1987/ec-validador-cedula-ruc)[ Docs](https://github.com/tavo1987/ec-validador-cedula-ruc)[ RSS](/packages/tavo1987-ec-validador-cedula-ruc/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (1)Versions (7)Used By (5)

Ecuador ID (Cedula) and RUC Validator
=====================================

[](#ecuador-id-cedula-and-ruc-validator)

[![](https://camo.githubusercontent.com/c0682db12daf65856def3aad5b0e7776421942fbd9ad7067ba56d9573bccfd43/687474703a2f2f7265732e636c6f7564696e6172792e636f6d2f656477696e2f696d6167652f75706c6f61642f76313439363039353436332f636564756c614c6f676f5f6c6d637438722e706e67)](https://camo.githubusercontent.com/c0682db12daf65856def3aad5b0e7776421942fbd9ad7067ba56d9573bccfd43/687474703a2f2f7265732e636c6f7564696e6172792e636f6d2f656477696e2f696d6167652f75706c6f61642f76313439363039353436332f636564756c614c6f676f5f6c6d637438722e706e67)

[![Tests](https://github.com/tavo1987/ec-validador-cedula-ruc/actions/workflows/tests.yml/badge.svg)](https://github.com/tavo1987/ec-validador-cedula-ruc/actions/workflows/tests.yml)[![PHP 8.2+](https://camo.githubusercontent.com/3ab08792c9151922aa5272a343694533ce85b4596bd3bdfb2cf8dce39446314c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e322b2d626c75652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tavo1987/ec-validador-cedula-ruc)[![License](https://camo.githubusercontent.com/7123c32787e013be5a8a13598ad01f562754637ed6141e89b02e85bf16d3e63e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6d6173686170652f6170697374617475732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tavo1987/ec-validador-cedula-ruc)[![Total Downloads](https://camo.githubusercontent.com/f39c6e9d89504bc54a5d696ea076b11f5e6c57a6f6876bcd0d715bd820cab735/68747470733a2f2f706f7365722e707567782e6f72672f7461766f313938372f65632d76616c696461646f722d636564756c612d7275632f646f776e6c6f616473)](https://packagist.org/packages/tavo1987/ec-validador-cedula-ruc)[![Latest Stable Version](https://camo.githubusercontent.com/d979a958ce51488d1f240326dd3deaaf1eef1d2493e639226a2abc41f4c0ee45/68747470733a2f2f706f7365722e707567782e6f72672f7461766f313938372f65632d76616c696461646f722d636564756c612d7275632f762f737461626c65)](https://packagist.org/packages/tavo1987/ec-validador-cedula-ruc)

A PHP library for validating Ecuadorian identification documents:

- **Cedula** (National ID - 10 digits)
- **RUC for Natural Persons** (13 digits, third digit 0-5)
- **RUC for Private Companies** (13 digits, third digit 9)
- **RUC for Public Companies** (13 digits, third digit 6)

Requirements
------------

[](#requirements)

- PHP 8.2 or higher

Installation
------------

[](#installation)

```
composer require tavo1987/ec-validador-cedula-ruc
```

Usage
-----

[](#usage)

### Basic Setup

[](#basic-setup)

```
require 'vendor/autoload.php';

use Tavo\ValidadorEc;

$validator = new ValidadorEc();
```

### Quick Validation (Static Methods)

[](#quick-validation-static-methods)

For simple validation without creating an instance:

```
// 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
```

### Universal Validation (Auto-detect document type)

[](#universal-validation-auto-detect-document-type)

The `validate()` method automatically detects and validates any document type:

```
// 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"
}
```

### Specific Validation Methods

[](#specific-validation-methods)

If you know the document type beforehand:

```
// 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';
}
```

### Extract Cedula from RUC

[](#extract-cedula-from-ruc)

For Natural Person RUC, you can extract the cedula portion:

```
$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
```

### Available Constants

[](#available-constants)

```
ValidadorEc::TYPE_CEDULA       // 'cedula'
ValidadorEc::TYPE_RUC_NATURAL  // 'ruc_natural'
ValidadorEc::TYPE_RUC_PRIVATE  // 'ruc_private'
ValidadorEc::TYPE_RUC_PUBLIC   // 'ruc_public'
```

API Reference
-------------

[](#api-reference)

### Static Methods

[](#static-methods)

MethodDescription`ValidadorEc::isValid(string $number)`Quick validation of any document type`ValidadorEc::isValidCedula(string $number)`Quick cedula validation`ValidadorEc::isValidNaturalPersonRuc(string $number)`Quick natural person RUC validation`ValidadorEc::isValidPrivateCompanyRuc(string $number)`Quick private company RUC validation`ValidadorEc::isValidPublicCompanyRuc(string $number)`Quick public company RUC validation### Instance Methods

[](#instance-methods)

MethodDescription`validate(string $number)`Auto-detect and validate any document`validateCedula(string $number)`Validate Cedula (10 digits)`validateNaturalPersonRuc(string $number)`Validate Natural Person RUC (13 digits)`validatePrivateCompanyRuc(string $number)`Validate Private Company RUC (13 digits)`validatePublicCompanyRuc(string $number)`Validate Public Company RUC (13 digits)`extractCedulaFromRuc(string $ruc)`Extract cedula from natural person RUC`getDocumentType()`Get detected document type after validation`getError()`Get error message from last validationDocument Structure
------------------

[](#document-structure)

Document TypeDigitsThird DigitAlgorithmCedula100-5\*Modulo 10RUC Natural Person130-5\*Modulo 10RUC Private Company139Modulo 11RUC Public Company136Modulo 11\*For province code 30, third digit validation is skipped (see below).

### Province Codes

[](#province-codes)

The first two digits represent the province:

CodeProvince01Azuay02Bolivar03Cañar04Carchi05Cotopaxi06Chimborazo07El Oro08Esmeraldas09Guayas10Imbabura11Loja12Los Rios13Manabi14Morona Santiago15Napo16Pastaza17Pichincha18Tungurahua19Zamora Chinchipe20Galapagos21Sucumbios22Orellana23Santo Domingo de los Tsachilas24Santa Elena**30****Foreign residents**### Foreign Residents (Code 30)

[](#foreign-residents-code-30)

Province code 30 is for "ecuatorianos registrados en el exterior" (Ecuadorians abroad) and foreign residents:

- Third digit validation is skipped
- Check digit (Modulo 10) validation is still performed

Validation Limitations
----------------------

[](#validation-limitations)

This library uses algorithmic validation (Modulo 10/11). Known limitations:

1. **Foreign natural persons without cedula**: RUCs for foreigners may not follow standard validation. Verify through SRI web services.
2. **Critical applications**: Consider complementing with official SRI database queries.

Testing
-------

[](#testing)

```
# Run all tests
./vendor/bin/phpunit

# Run with coverage
./vendor/bin/phpunit --coverage-text
```

Changelog
---------

[](#changelog)

### v2.0.0

[](#v200)

- **Breaking**: Minimum PHP version is now 8.2
- **Breaking**: All method names now in English
- **Breaking**: Constants renamed (`TIPO_*` → `TYPE_*`)
- **Breaking**: Removed all Spanish method names
- New universal `validate()` method with auto-detection
- New `getDocumentType()` method
- New static methods for quick validation (`isValid()`, `isValidCedula()`, etc.)
- New `extractCedulaFromRuc()` method to extract cedula from natural person RUC
- Support for province code 30 (foreign residents)
- Class is now `final`
- Optimized with `match` expressions
- 93 comprehensive tests

### v1.0.2

[](#v102)

- Fixed namespace issues

### v1.0.0

[](#v100)

- Initial release

License
-------

[](#license)

MIT License - see [LICENSE](LICENCE) file for details.

Authors
-------

[](#authors)

**Edwin Ramirez**

- Twitter: [@edwin\_tavo](https://twitter.com/edwin_tavo)
- GitHub: [@tavo1987](https://github.com/tavo1987)

**Bryan Suarez**

- Twitter: [@BryanSC\_7](https://twitter.com/BryanSC_7)

###  Health Score

58

—

FairBetter than 98% of packages

Maintenance76

Regular maintenance activity

Popularity38

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 87% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~786 days

Total

5

Last Release

130d ago

Major Versions

v1.0.2 → v2.0.02026-01-07

PHP version history (2 changes)v1.0.0PHP &gt;=5.4.0

v2.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/1b19bb2aa677676beca5748abd4ba8aec0f8123582efe9d52e51cfbe33bd40e5?d=identicon)[tavo1987](/maintainers/tavo1987)

---

Top Contributors

[![tavo1987](https://avatars.githubusercontent.com/u/9807894?v=4)](https://github.com/tavo1987 "tavo1987 (20 commits)")[![BryanSuarez](https://avatars.githubusercontent.com/u/14984818?v=4)](https://github.com/BryanSuarez "BryanSuarez (3 commits)")

---

Tags

cedulacomposerecuadorpaquetephprucvalidador-de-cpfvalidatorvalidatoridentificationruccedulaecuadortax-id

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tavo1987-ec-validador-cedula-ruc/health.svg)

```
[![Health](https://phpackages.com/badges/tavo1987-ec-validador-cedula-ruc/health.svg)](https://phpackages.com/packages/tavo1987-ec-validador-cedula-ruc)
```

###  Alternatives

[respect/validation

The most awesome validation engine ever created for PHP

5.9k37.4M383](/packages/respect-validation)[seld/jsonlint

JSON Linter

1.3k217.8M205](/packages/seld-jsonlint)[composer/spdx-licenses

SPDX licenses list and validation library.

1.4k184.2M25](/packages/composer-spdx-licenses)[opis/json-schema

Json Schema Validator for PHP

64236.9M186](/packages/opis-json-schema)[intervention/validation

Additional validation rules for the Laravel framework

6826.7M8](/packages/intervention-validation)[laminas/laminas-validator

Validation classes for a wide range of domains, and the ability to chain validators to create complex validation criteria

15544.9M188](/packages/laminas-laminas-validator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
