PHPackages                             dannyps/ccidadao - 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. dannyps/ccidadao

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

dannyps/ccidadao
================

A class for generating and validating Portuguese Citizen Card (CC aka Cartão de Cidadão) Numbers.

v1.0.1(1y ago)871MITPHPPHP &gt;=7.0.0 || &gt;=8.0.0CI passing

Since Dec 4Pushed 1y agoCompare

[ Source](https://github.com/Dannyps/CCidadao)[ Packagist](https://packagist.org/packages/dannyps/ccidadao)[ RSS](/packages/dannyps-ccidadao/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

CCidadao
========

[](#ccidadao)

CCidadao is a PHP Class used to validate and generate Citizen Card numbers.

How to use
----------

[](#how-to-use)

### Instalation

[](#instalation)

CCidadao is available on [Packagist](https://packagist.org/)! You can install it via [Composer](https://getcomposer.org/), by typing:

`$ composer require Dannyps/CCidadao`

The class will be auto-loaded by composer. Thus, in order to use it, you need only `require 'vendor/autoload.php';` in your PHP script.

### Softening the curve

[](#softening-the-curve)

Portuguese Citizen Cards are a complicated subject. They have two check digits, and a weird version control system. Internal variables contain the following fields:

In the example number:

```
12345678 9 ZZ 0
┃        ┃ ┃  ┃
┃        ┃ ┃  ┗━━━> Versioned check digit ----> $vcd
┃        ┃ ┗━━━━━━> Version chars ------------> $vcc
┃        ┗━━━━━━━━> Constant check digit -----> $ccd
┗━━━━━━━━━━━━━━━━━> the number itself --------> $num

```

- The version chars represent the version of the document in the following manner:

- ZZ =&gt; v1
- ZY =&gt; v2
- ZX =&gt; v3
- ...
- ZA =&gt; v26
- YZ =&gt; v27
- etc... Both `$ccd` and `$vcd` can be determined, provided the `$num` and `$ver/$vcc` are available, respectively.

Moreover, the `$ccd` depends solely on the `$num`, whereas the `$vcd` depends on the `$num` and on the `$vcc`.

### Code Examples

[](#code-examples)

Test code is a good place to start. However, code examples are displayed below for your convenience.

#### Generating an array of *valid* CC numbers.

[](#generating-an-array-of-valid-cc-numbers)

*Note: The fact these numbers are valid does not mean they are being used by anyone.*

```
