Search by

andyhatestheworld / romanian-cnp-validator

andyhatestheworld

Validate, parse and generate Romanian personal numeric codes (CNP). Zero dependencies, typed, rules backed by official sources.

Package info

github.com/andyhatestheworld/romanian-cnp-validator

Language:Python

pkg:composer/andyhatestheworld/romanian-cnp-validator

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 5

v1.0.0 2026-12-02 22:47 UTC

This package is auto-updated.

Last update: 2026-12-03 04:50:07 UTC


README

romanian_cnp_validator: validate, parse and generate Romanian CNPs

CI License: MIT npm PyPI crates.io NuGet Maven Central Packagist Go Reference

Romanian CNP Validator

Validate, parse and generate Romanian personal numeric codes (CNP, Cod Numeric Personal): zero dependencies, fully typed, and every rule backed by an official source you can check yourself.

If this saved you time, consider leaving a star - it helps others find it.

Live demo: every function of the library in your browser, with each rule explained. Nothing you type leaves the page.

Almost every Romanian app that touches people (sign-up forms, invoices, HR, healthcare, banking) ends up writing its own CNP check. Most of those checks stop at the control digit and miss the rest: 29 February 1900, the abolished Bucharest sectors, foreign residents, the new county code 70, or the 9... numbers that look like a CNP but are not one. This project solves the problem once, documents why each rule exists, and runs the same shared test suite against every language package.

What's in it

Feature What it does
Validate Full check: length, digits, sex/century digit, real calendar date (leap years included), not in the future, county code valid for that birth date, sequence number, control digit. Tells you exactly what is wrong.
Parse Sex, birth date, age, county (name, ISO 3166-2 code), resident status, sequence number.
Generate Valid CNPs from preferences (sex, exact date or age range, county, resident) for tests and mock data, with a seedable random source.
Language Package Status
JavaScript / TypeScript packages/javascript, npm romanian-cnp-validator available
Python packages/python, PyPI romanian-cnp-validator available
PHP packages/php, Packagist andyhatestheworld/romanian-cnp-validator available
C / C++ packages/c, CMake (FetchContent) available
C# / .NET packages/csharp, NuGet RomanianCnpValidator available
Java / Kotlin packages/java, Maven Central io.github.andyhatestheworld:romanian-cnp-validator available
Go packages/go, go get github.com/andyhatestheworld/romanian-cnp-validator/packages/go available
Rust packages/rust, crates.io romanian-cnp-validator available
Swift packages/swift, Swift Package Manager (this repository's URL) available

Use it now (CDN)

No install and no build step: drop one script tag in your page.

<script src="https://cdn.jsdelivr.net/npm/romanian-cnp-validator@1/dist/cnp.min.js"></script>
<script>
  RomanianCNP.isValid('1900101120013');        // true
  RomanianCNP.parse('1900101120013').birthDate; // "1990-01-01"
</script>

Prefer unpkg? https://unpkg.com/romanian-cnp-validator@1/dist/cnp.min.js works the same way. For production, pin an exact version (@1.0.0).

The build is also committed to this repository, so jsDelivr can serve it straight from GitHub:

<script src="https://cdn.jsdelivr.net/gh/andyhatestheworld/romanian-cnp-validator@v1.0.0/packages/javascript/dist/cnp.min.js"></script>

Use a release tag (@v1.0.0), not @main: a branch moves with every commit.

Install

npm install romanian-cnp-validator     # JavaScript / TypeScript
pip install romanian-cnp-validator     # Python
composer require andyhatestheworld/romanian-cnp-validator   # PHP

For C and C++, add the library to a CMake project (3.16+):

include(FetchContent)
FetchContent_Declare(romanian_cnp
    GIT_REPOSITORY https://github.com/andyhatestheworld/romanian-cnp-validator.git
    GIT_TAG v1.0.0
    SOURCE_SUBDIR packages/c)
FetchContent_MakeAvailable(romanian_cnp)
target_link_libraries(your_app PRIVATE romanian_cnp::romanian_cnp)

Not using CMake? Compile packages/c/src/cnp.c and packages/c/src/cnp_counties.c with your project and add packages/c/include to the include path.

For .NET:

dotnet add package RomanianCnpValidator

For Java and Kotlin (Maven, or Gradle with implementation("io.github.andyhatestheworld:romanian-cnp-validator:1.0.0")):

<dependency>
  <groupId>io.github.andyhatestheworld</groupId>
  <artifactId>romanian-cnp-validator</artifactId>
  <version>1.0.0</version>
</dependency>

For Go:

go get github.com/andyhatestheworld/romanian-cnp-validator/packages/go

For Rust:

cargo add romanian-cnp-validator

For Swift, add the package in Xcode (File > Add Package Dependencies) or in Package.swift:

.package(url: "https://github.com/andyhatestheworld/romanian-cnp-validator.git", from: "1.0.0")
  • JavaScript: works with ESM, CommonJS and TypeScript (types included), on Node 22+ and in all modern browsers.
  • Python: works on Python 3.11+, with no dependencies and full type hints (py.typed).
  • PHP: works on PHP 8.3+, with no dependencies, strict types and PHPStan-clean at the highest level.
  • C / C++: the core is C11, with no heap allocation and no dependencies, so any language with a C FFI can call it. cnp.hpp adds a C++17 API on top. It is tested with MSVC, GCC and Clang, with warnings treated as errors.
  • C# / .NET: targets .NET Standard 2.0 and .NET 8, so it runs on .NET Framework 4.6.1+, .NET 5 to 10, Unity and Xamarin. No dependencies, nullable annotations, trimming- and AOT-friendly.
  • Java / Kotlin: Java 17+, with no dependencies. Uses records and java.time.LocalDate, and works from Kotlin and on Android as-is. Compiled with all warnings as errors.
  • Go: Go 1.26+, standard library only. gofmt- and go vet-clean.
  • Rust: Rust 1.70+, no dependencies (not even for the tests), no unsafe, clippy- and rustfmt-clean.
  • Swift: Swift 5.7+, no dependencies besides Foundation, for iOS, macOS, Linux and Windows. No Apple account is needed to use or publish it.

Every package has the same functions and error codes. Each one follows its language's conventions:

  • Names: JavaScript and PHP use isValid and birthDate. Python uses snake_case, so is_valid and birth_date.
  • Calls: in PHP everything is a static method on the Cnp class, such as Cnp::isValid().
  • C / C++: C++ uses snake_case like the standard library (is_valid, birth_date). C prefixes every name with cnp_: cnp_is_valid, CNP_INVALID_DATE.
  • C#: uses .NET's PascalCase (Cnp.IsValid, BirthDate). It also has the .NET-style Cnp.TryParse.
  • Java: uses camelCase like JavaScript (Cnp.isValid, birthDate()). parse returns an Optional, and the error constants are named exactly like the shared codes (CnpError.INVALID_DATE).
  • Go: errors are values. Validate returns nil or a *ValidationError, Parse returns (Info, error), and Generate takes functional options (cnp.WithSex(cnp.Female)). The functions ending in At take a reference date.
  • Rust: snake_case like Python. validate and parse return a Result with a CnpError enum, and Generator is a builder (Generator::new().sex(Sex::Female).generate()). The *_at functions take a reference date. Without one, Rust uses today's date in UTC, because its standard library has no local time zone.
  • Swift: camelCase. Cnp.parse throws a CnpError, Cnp.validationError returns one (or nil), and the reference date is an at: argument (Cnp.parse(cnp, at: date)).

Try it in 30 seconds (playgrounds)

The quickest way needs nothing at all: open the live demo. It is built from site/index.html and the current JavaScript build on every push to main.

Clone the repository and every language has a playground: validate and parse a CNP, generate CNPs, and run the shared test vectors or your own tests. None of them needs an install step.

git clone https://github.com/andyhatestheworld/romanian-cnp-validator.git
cd romanian-cnp-validator
Language Start it Run the tests Details
JavaScript open examples/javascript/playground.html in a browser buttons on the page browser playground
Python 3.11+ python examples/python/playground.py python examples/python/playground.py test vectors Python playground
PHP 8.3+ php examples/php/playground.php php examples/php/playground.php test vectors PHP playground
C / C++ (CMake) build once (below), then build/c/cnp_playground build/c/cnp_playground test vectors C/C++ playground
C# (.NET SDK 10) dotnet run --project examples/csharp dotnet run --project examples/csharp -- test vectors C# playground
Java 17+ build once (below), then java -cp packages/java/target/classes examples/java/Playground.java same, plus test vectors Java playground
Go 1.26+ go -C examples/go run . go -C examples/go run . test vectors Go playground
Rust 1.70+ cargo run -q --manifest-path examples/rust/Cargo.toml same, plus -- test vectors Rust playground
Swift 5.7+ swift run -c release cnp-playground same, plus test vectors Swift playground

To open the browser playground from a terminal:

start examples/javascript/playground.html      # Windows
open examples/javascript/playground.html       # macOS
xdg-open examples/javascript/playground.html   # Linux

To build the C/C++ playground (needs CMake 3.16+ and a C/C++ compiler):

cmake -S packages/c -B build/c
cmake --build build/c

On Windows with Visual Studio, run powershell -ExecutionPolicy Bypass -File scripts\build-c.ps1 instead (see below).

To build the Java playground once: cd packages/java && ./mvnw -q compile (on Windows: mvnw.cmd -q compile). The Maven Wrapper downloads Maven by itself, so only a JDK 17+ is needed.

The terminal playgrounds (Python, PHP, C/C++, C#, Java, Go, Rust, Swift) also run test mine (your cases from my_tests.txt) and test stress (generator stress test). Without a command, they open an interactive menu.

Usage: JavaScript / TypeScript

Validate

import { isValid, validate } from 'romanian-cnp-validator';

isValid('1900101120013'); // true

validate('1900101120014');
// { valid: false, error: 'INVALID_CONTROL_DIGIT', message: 'The control digit (last digit) does not match.' }

validate('9900101120011');
// { valid: false, error: 'NIF_NOT_CNP', message: 'A first digit of 9 marks a fiscal identification number (NIF) issued by ANAF, not a CNP.' }

The input must be a string of exactly 13 digits. Spaces and separators are not stripped silently: clean user input yourself (input.replace(/\s/g, '')) if that's what you want.

Error code Meaning
NOT_A_STRING The input is not a string.
INVALID_LENGTH Not exactly 13 characters.
NON_DIGIT Contains something other than 0-9.
INVALID_SEX_DIGIT First digit is 0.
NIF_NOT_CNP First digit is 9: an ANAF fiscal number, not a CNP (why).
INVALID_DATE YYMMDD is not a real date (13th month, 31 April, 29 February 1900).
FUTURE_DATE Birth date is after today.
INVALID_COUNTY JJ is not a known code.
COUNTY_NOT_VALID_FOR_DATE Bucharest sector 7 or 8 used for someone born after they were abolished.
INVALID_SEQUENCE NNN is 000.
INVALID_CONTROL_DIGIT Last digit does not match the checksum.

Parse

import { parse } from 'romanian-cnp-validator';

parse('2851231431232');
// {
//   cnp: '2851231431232',
//   sex: 'female',
//   birthDate: '1985-12-31', year: 1985, month: 12, day: 31,
//   age: 40,                     // on 2026-12-01
//   centuryInferred: false,
//   resident: false,
//   county: { code: '43', name: 'București, Sectorul 3', iso3166_2: 'RO-B', type: 'sector', validUntil: null },
//   sequence: 123,
//   controlDigit: 2
// }

parse('not a cnp'); // null (use validate() to find out why)

Generate

import { generate } from 'romanian-cnp-validator';

generate();                                           // fully random, valid CNP
generate({ sex: 'female', minAge: 18, maxAge: 30 });  // an adult woman under 31
generate({ birthDate: '2000-02-29', county: '12' });  // born on a leap day in Cluj
generate({ resident: true, sex: 'male' });            // foreign resident (S = 7)

Need the same "random" data on every test run? Pass your own seeded PRNG: generate({ random: mySeededRandom }).

Options shared by every function

validate, isValid, parse and generate accept a referenceDate (a Date or a YYYY-MM-DD string). It is the "today" used to reject future dates, compute ages and infer the century for residents. Pin it in tests so they never start failing on New Year's Eve.

Extras

import { COUNTIES, getCounty, computeControlDigit, CONTROL_KEY } from 'romanian-cnp-validator';

getCounty('35');                        // { code: '35', name: 'Timiș', iso3166_2: 'RO-TM', ... }
computeControlDigit('190010112001');    // 3
CONTROL_KEY;                            // '279146358279'

Try it in your browser (playground)

examples/javascript/playground.html is a single page that loads the local JavaScript build. You don't need a server: clone the repository and open the file in any browser, or from a terminal:

start examples/javascript/playground.html      # Windows
open examples/javascript/playground.html       # macOS
xdg-open examples/javascript/playground.html   # Linux
  • Validate & parse: type a CNP to see on the spot whether it is valid, why not, and everything it encodes.
  • Generate: pick sex, age range, county and resident status, then generate one CNP or ten. Click a generated CNP to check it.
  • Automatic tests:
    1. Shared test vectors runs every case from spec/test-vectors.json (the same ones npm test runs) and shows PASS or FAIL for each.
    2. Your own tests checks cases you write yourself, one per line, against the date you choose. Your tests are saved in the browser:
      # CNP           expected                 optional field checks (only after "valid")
      1900101120013   valid                    sex=male birthDate=1990-01-01 county=12
      1900101120014   INVALID_CONTROL_DIGIT
      
      After valid you can also check sex=, birthDate=, age=, county=, resident= and sequence=.
    3. Generator stress test generates thousands of CNPs with random options and checks that each one validates and matches what was asked for.

The playground uses packages/javascript/dist/cnp.min.js. If you change the source, run npm run build in packages/javascript and reload the page.

Usage: Python

Validate

from romanian_cnp_validator import CnpError, is_valid, validate

is_valid("1900101120013")  # True

result = validate("1900101120014")
result.valid    # False (the result itself is falsy too: `if not result: ...`)
result.error    # CnpError.INVALID_CONTROL_DIGIT
result.message  # 'The control digit (last digit) does not match.'

validate("9900101120011").error == "NIF_NOT_CNP"  # True: error codes are also plain strings

The error codes are the same as in the JavaScript table above.

Parse

from romanian_cnp_validator import parse

info = parse("2851231431232")
info.sex               # 'female'
info.birth_date        # datetime.date(1985, 12, 31)
info.age               # 40 (on 2026-12-01)
info.century_inferred  # False
info.resident          # False
info.county            # County(code='43', name='București, Sectorul 3', iso3166_2='RO-B', type='sector', valid_until=None)
info.sequence          # 123
info.control_digit     # 2

parse("not a cnp")     # None (use validate() to find out why)

CnpInfo and County are frozen dataclasses: you can compare and hash them, but not change them.

Generate

import random
from romanian_cnp_validator import generate

generate()                                         # fully random, valid CNP
generate(sex="female", min_age=18, max_age=30)     # an adult woman under 31
generate(birth_date="2000-02-29", county="12")     # born on a leap day in Cluj
generate(resident=True, sex="male")                # foreign resident (S = 7)
generate(rng=random.Random(42))                    # same result on every run

Every function accepts a keyword-only reference_date: a date, a datetime or a YYYY-MM-DD string. It works like referenceDate in JavaScript. Invalid options raise ValueError.

Extras

from romanian_cnp_validator import COUNTIES, CONTROL_KEY, compute_control_digit, get_county

get_county("35").name                   # 'Timiș'
compute_control_digit("190010112001")   # 3
CONTROL_KEY                             # '279146358279'

Try it in your terminal (Python playground)

examples/python/playground.py runs the local source in packages/python/src, so you don't need to install anything (Python 3.11+, standard library only). Run it without arguments for an interactive menu:

python examples/python/playground.py

You can also call each command directly:

python examples/python/playground.py validate 1900101120013 1000229120017
python examples/python/playground.py generate --sex female --min-age 18 --max-age 30 --county 12 --count 5 --seed 42
python examples/python/playground.py test vectors              # the shared test vectors
python examples/python/playground.py test mine                 # your tests from examples/python/my_tests.txt
python examples/python/playground.py test mine other.txt --date 2026-12-01 -v
python examples/python/playground.py test stress --count 20000 # generator stress test
  • validate prints every field of a valid CNP, or the error code and message.
  • generate takes the same options as generate(), plus --count and --seed.
  • test runs one of three suites. Add -v to list the passing tests too. The command exits with code 1 if any test fails, so you can use it in scripts.
    • vectors runs every case from spec/test-vectors.json.
    • mine runs your own cases from examples/python/my_tests.txt. The format is the same in every playground (CNP expected field=value ...), so you can copy tests between them.
    • stress generates CNPs with random options and checks that each one validates and matches what was asked for.

Usage: PHP

Validate

use RomanianCnpValidator\Cnp;
use RomanianCnpValidator\CnpError;

Cnp::isValid('1900101120013');  // true

$result = Cnp::validate('1900101120014');
$result->valid;    // false
$result->error;    // CnpError::InvalidControlDigit
$result->message;  // 'The control digit (last digit) does not match.'

Cnp::validate('9900101120011')->error->value;  // 'NIF_NOT_CNP'

CnpError is a string-backed enum. Its ->value is the same error code used by every package, and ->message() gives the human-readable text. The codes are listed in the JavaScript table above.

Parse

$info = Cnp::parse('2851231431232');
$info->sex;                         // Sex::Female (->value is 'female')
$info->birthDate->format('Y-m-d');  // '1985-12-31'
$info->age;                         // 40 (on 2026-12-01)
$info->centuryInferred;             // false
$info->resident;                    // false
$info->county->name;                // 'București, Sectorul 3'
$info->county->iso3166_2;           // 'RO-B'
$info->sequence;                    // 123
$info->controlDigit;                // 2

Cnp::parse('not a cnp');            // null (use validate() to find out why)

CnpInfo, County and ValidationResult are readonly classes. Dates are DateTimeImmutable at midnight UTC, so the server's time zone never changes the result.

Generate

use Random\Engine\Mt19937;
use Random\Randomizer;
use RomanianCnpValidator\Sex;

Cnp::generate();                                          // fully random, valid CNP
Cnp::generate(sex: 'female', minAge: 18, maxAge: 30);     // an adult woman under 31
Cnp::generate(birthDate: '2000-02-29', county: '12');     // born on a leap day in Cluj
Cnp::generate(sex: Sex::Male, resident: true);            // foreign resident (S = 7)
Cnp::generate(random: new Randomizer(new Mt19937(42)));   // same result on every run

Every method accepts a referenceDate (a DateTimeInterface or a YYYY-MM-DD string). It works like referenceDate in JavaScript. Invalid options throw InvalidArgumentException.

Extras

Cnp::getCounty('35')->name;               // 'Timiș'
Cnp::counties();                          // the full JJ table, list<County>
Cnp::computeControlDigit('190010112001'); // 3
Cnp::CONTROL_KEY;                         // '279146358279'

Try it in your terminal (PHP playground)

examples/php/playground.php loads the local source in packages/php/src directly, so it runs without composer install (PHP 8.3+). It has the same commands as the Python playground:

php examples/php/playground.php                                   # interactive menu
php examples/php/playground.php validate 1900101120013
php examples/php/playground.php generate --sex=female --min-age=18 --max-age=30 --count=5 --seed=42
php examples/php/playground.php test vectors
php examples/php/playground.php test mine                         # your tests from examples/php/my_tests.txt
php examples/php/playground.php test stress --count=20000

Options use the --name=value form. The test commands exit with code 1 if a test fails. examples/php/my_tests.txt uses the same format as the other playgrounds.

Usage: C / C++

C++

#include <romanian_cnp/cnp.hpp>
namespace cnp = romanian_cnp;

cnp::is_valid("1900101120013");                 // true

auto result = cnp::validate("1900101120014");
result.valid;                                   // false (the result also converts to bool)
cnp::error_code(*result.error);                 // "INVALID_CONTROL_DIGIT"
result.message;                                 // "The control digit (last digit) does not match."

auto info = cnp::parse("2851231431232");        // std::optional<cnp::Info>
info->sex;                                      // cnp::Sex::Female
info->birth_date.iso();                         // "1985-12-31"
info->age;                                      // 40 (on 2026-12-01)
info->county.name;                              // "București, Sectorul 3" (UTF-8)
info->county.iso3166_2;                         // "RO-B" (std::optional, empty for code 70)

cnp::GenerateOptions o;
o.sex = cnp::Sex::Female;
o.min_age = 18;
o.max_age = 30;
cnp::generate(o);                               // an adult woman under 31

cnp::Rng rng(42);
o.rng = &rng;
cnp::generate(o);                               // same sequence of results on every run

Every function takes an optional cnp::Date as reference_date, which works like referenceDate in JavaScript. Date::parse("2026-12-01") builds one from a string. Invalid options throw std::invalid_argument. cnp::counties(), cnp::get_county("35"), cnp::compute_control_digit("190010112001") and cnp::CONTROL_KEY work like in the other languages.

C

#include <romanian_cnp/cnp.h>

cnp_info info;
cnp_error e = cnp_validate("2851231431232", NULL, &info);  /* NULL reference date = today */
if (e == CNP_OK) {
    char iso[11];
    cnp_date_format(info.birth_date, iso);                 /* "1985-12-31" */
    printf("%s, %d, %s\n", iso, info.age, info.county->name);
} else {
    printf("%s: %s\n", cnp_error_code(e), cnp_error_message(e));
}

cnp_rng rng;
cnp_rng_seed(&rng, 42);
cnp_generate_options o = cnp_generate_defaults();
o.sex = CNP_SEX_FEMALE;
o.min_age = 18;
o.max_age = 30;
o.rng = &rng;
char out[CNP_LENGTH + 1], message[200];
if (cnp_generate(&o, out, message, sizeof message) != CNP_OK) puts(message);

The C API never allocates memory. All strings it returns (county names, error messages) are static. Invalid options return CNP_INVALID_ARGUMENT, with an explanation written to your buffer. Without your own cnp_rng, cnp_generate uses an internal generator that is not thread-safe. Give each thread its own cnp_rng.

Try it in your terminal (C/C++ playground)

examples/c/playground.cpp is built together with the library, and has the same commands as the Python and PHP playgrounds:

cmake -S packages/c -B build/c
cmake --build build/c
build/c/cnp_playground                                            # interactive menu
build/c/cnp_playground validate 1900101120013
build/c/cnp_playground generate --sex=female --min-age=18 --max-age=30 --count=5 --seed=42
build/c/cnp_playground test vectors
build/c/cnp_playground test mine                                  # your tests from examples/c/my_tests.txt
build/c/cnp_playground test stress --count=20000

The tests run with ctest --test-dir build/c.

On Windows with Visual Studio: Visual Studio includes CMake, but not on the normal PATH. The script below finds Visual Studio, loads its developer environment, then builds and runs the tests. It works from any PowerShell window and any folder:

powershell -ExecutionPolicy Bypass -File scripts\build-c.ps1
.\build\c\cnp_playground.exe

You can also run the cmake commands above yourself, from Developer PowerShell for VS 2022 (Start menu). Add -G Ninja so the program lands in build/c/ rather than build/c/Debug/.

Usage: C# / .NET

using RomanianCnpValidator;

Cnp.IsValid("1900101120013");                   // true

var result = Cnp.Validate("1900101120014");
result.Valid;                                   // false (the result also converts to bool: if (!result) ...)
result.Error;                                   // CnpError.InvalidControlDigit
result.Error?.ToCode();                         // "INVALID_CONTROL_DIGIT"
result.Message;                                 // "The control digit (last digit) does not match."

var info = Cnp.Parse("2851231431232");          // CnpInfo? (null when invalid)
info.Sex;                                       // Sex.Female
info.BirthDate;                                 // 1985-12-31 (DateTime, time 00:00)
info.Age;                                       // 40 (on 2026-12-01)
info.County.Name;                               // "București, Sectorul 3"
info.County.Iso3166_2;                          // "RO-B" (null for code 70)

if (Cnp.TryParse(input, out var parsed)) { /* ... */ }

Cnp.Generate(new GenerateOptions { Sex = Sex.Female, MinAge = 18, MaxAge = 30 });
Cnp.Generate(new GenerateOptions { BirthDate = new DateTime(2000, 2, 29), County = "12" });
Cnp.Generate(new GenerateOptions { Resident = true, Random = new Random(42) });  // same result on every run

Every method takes an optional referenceDate (a DateTime, only its date part is used). It works like referenceDate in JavaScript. CnpInfo, County and ValidationResult are immutable records. Invalid options throw ArgumentException. Cnp.Counties, Cnp.GetCounty("35"), Cnp.ComputeControlDigit("190010112001") and Cnp.ControlKey work like in the other languages.

Try it in your terminal (C# playground)

examples/csharp is a console project that references the local source. It has the same commands as the other terminal playgrounds. Arguments go after --:

dotnet run --project examples/csharp                                          # interactive menu
dotnet run --project examples/csharp -- validate 1900101120013
dotnet run --project examples/csharp -- generate --sex=female --min-age=18 --max-age=30 --count=5 --seed=42
dotnet run --project examples/csharp -- test vectors
dotnet run --project examples/csharp -- test mine                             # your tests from examples/csharp/my_tests.txt
dotnet run --project examples/csharp -- test stress --count=20000

The package tests run with dotnet test packages/csharp/tests/RomanianCnpValidator.Tests.

Usage: Java / Kotlin

import io.github.andyhatestheworld.cnp.*;

Cnp.isValid("1900101120013");                       // true

ValidationResult result = Cnp.validate("1900101120014");
result.valid();                                     // false
result.error();                                     // CnpError.INVALID_CONTROL_DIGIT (name() is the shared code)
result.message();                                   // "The control digit (last digit) does not match."

CnpInfo info = Cnp.parse("2851231431232").orElseThrow();   // Optional<CnpInfo>, empty when invalid
info.sex();                                         // Sex.FEMALE
info.birthDate();                                   // 1985-12-31 (LocalDate)
info.age();                                         // 40 (on 2026-12-01)
info.county().name();                               // "București, Sectorul 3"
info.county().iso();                                // Optional[RO-B] (empty for code 70)

Cnp.generate(GenerateOptions.builder().sex(Sex.FEMALE).minAge(18).maxAge(30).build());
Cnp.generate(GenerateOptions.builder().birthDate(LocalDate.of(2000, 2, 29)).county("12").build());
Cnp.generate(GenerateOptions.builder().resident(true).random(new Random(42)).build());  // same result on every run

From Kotlin the same calls read naturally: Cnp.parse(cnp).orElse(null)?.county?.name.

Every method has an overload taking a LocalDate referenceDate, which works like referenceDate in JavaScript. CnpInfo, County and ValidationResult are immutable records. Invalid options throw IllegalArgumentException. Cnp.counties(), Cnp.getCounty("35"), Cnp.computeControlDigit("190010112001") and Cnp.CONTROL_KEY work like in the other languages. The jar declares the module name io.github.andyhatestheworld.cnp for the Java module system.

Try it in your terminal (Java playground)

examples/java/Playground.java is a single file that Java 17+ runs directly, without a separate javac step. Compile the library once, then:

cd packages/java && ./mvnw -q compile && cd ../..             # Windows: mvnw.cmd -q compile
java -cp packages/java/target/classes examples/java/Playground.java                         # interactive menu
java -cp packages/java/target/classes examples/java/Playground.java validate 1900101120013
java -cp packages/java/target/classes examples/java/Playground.java generate --sex=female --min-age=18 --max-age=30 --count=5 --seed=42
java -cp packages/java/target/classes examples/java/Playground.java test vectors
java -cp packages/java/target/classes examples/java/Playground.java test mine                # examples/java/my_tests.txt
java -cp packages/java/target/classes examples/java/Playground.java test stress --count=20000

The package tests run with ./mvnw verify in packages/java. Besides the tests, this command builds the jar, sources and Javadoc that Maven Central needs.

Usage: Go

import cnp "github.com/andyhatestheworld/romanian-cnp-validator/packages/go"

cnp.IsValid("1900101120013")                        // true

err := cnp.Validate("1900101120014")                // nil when valid
cnp.ErrorCode(err)                                  // cnp.InvalidControlDigit ("INVALID_CONTROL_DIGIT")
err.Error()                                         // "INVALID_CONTROL_DIGIT: The control digit (last digit) does not match."

info, err := cnp.Parse("2851231431232")
info.Sex                                            // cnp.Female (String() is "female")
info.BirthDate                                      // 1985-12-31, midnight UTC (time.Time)
info.Age                                            // 40 (on 2026-12-01)
info.County.Name                                    // "București, Sectorul 3"
info.County.ISO3166_2                               // "RO-B" ("" for code 70)

cnp.Generate(cnp.WithSex(cnp.Female), cnp.WithAgeRange(18, 30))
cnp.Generate(cnp.WithBirthDate(time.Date(2000, 2, 29, 0, 0, 0, 0, time.UTC)), cnp.WithCounty("12"))
cnp.Generate(cnp.WithResident(), cnp.WithRand(rand.New(rand.NewPCG(42, 42))))  // same result on every run

ValidateAt, IsValidAt, ParseAt and cnp.WithReferenceDate take a reference date (a time.Time; only its calendar date, in its own location, is used). It works like referenceDate in JavaScript. Use errors.As(err, &v) with a *cnp.ValidationError, or the shorter cnp.ErrorCode(err). cnp.Counties(), cnp.GetCounty("35"), cnp.ComputeControlDigit("190010112001") and cnp.ControlKey work like in the other languages.

Try it in your terminal (Go playground)

examples/go is a small module that uses the local source. It has the same commands as the other terminal playgrounds:

go -C examples/go run .                                         # interactive menu
go -C examples/go run . validate 1900101120013
go -C examples/go run . generate --sex=female --min-age=18 --max-age=30 --count=5 --seed=42
go -C examples/go run . test vectors
go -C examples/go run . test mine                               # your tests from examples/go/my_tests.txt
go -C examples/go run . test stress --count=20000

The package tests run with go -C packages/go test ./....

Usage: Rust

use romanian_cnp_validator::{self as cnp, CnpError, Date, Generator, Sex};

cnp::is_valid("1900101120013");                     // true

let err = cnp::validate("1900101120014").unwrap_err();
err;                                                // CnpError::InvalidControlDigit
err.code();                                         // "INVALID_CONTROL_DIGIT"
err.to_string();                                    // "INVALID_CONTROL_DIGIT: The control digit (last digit) does not match."

let info = cnp::parse("2851231431232")?;            // Result<Info, CnpError>
info.sex;                                           // Sex::Female
info.birth_date;                                    // Date { year: 1985, month: 12, day: 31 } (Display: "1985-12-31")
info.age;                                           // 40 (on 2026-12-01)
info.county.name;                                   // "București, Sectorul 3"
info.county.iso3166_2;                              // Some("RO-B") (None for code 70)

Generator::new().sex(Sex::Female).age_range(18, 30).generate()?;
Generator::new().birth_date(Date::parse("2000-02-29")?).county("12").generate()?;
Generator::new().resident().seed(42).generate()?;   // same result on every run

validate_at, is_valid_at, parse_at and Generator::reference_date take a reference date (Date::new(2026, 12, 1) or Date::parse("2026-12-01")). It works like referenceDate in JavaScript. Without one, today's date in UTC is used, because Rust's standard library has no local time zone. Invalid options return a GenerateError. cnp::counties(), cnp::get_county("35"), cnp::compute_control_digit("190010112001") (an Option<u8>) and cnp::CONTROL_KEY work like in the other languages. The crate has its own small Date type and random generator (SplitMix64), so it needs no chrono or rand.

Try it in your terminal (Rust playground)

examples/rust is a small crate that uses the local source. It has the same commands as the other terminal playgrounds. Arguments go after --:

cargo run -q --manifest-path examples/rust/Cargo.toml                                         # interactive menu
cargo run -q --manifest-path examples/rust/Cargo.toml -- validate 1900101120013
cargo run -q --manifest-path examples/rust/Cargo.toml -- generate --sex=female --min-age=18 --max-age=30 --count=5 --seed=42
cargo run -q --manifest-path examples/rust/Cargo.toml -- test vectors
cargo run -q --manifest-path examples/rust/Cargo.toml -- test mine                            # examples/rust/my_tests.txt
cargo run -q --manifest-path examples/rust/Cargo.toml -- test stress --count=20000

The package tests run with cargo test --manifest-path packages/rust/Cargo.toml.

Usage: Swift

import RomanianCnpValidator

Cnp.isValid("1900101120013")                        // true

let error = Cnp.validationError("1900101120014")    // nil when valid
error                                               // CnpError.invalidControlDigit
error?.code                                         // "INVALID_CONTROL_DIGIT"
error?.message                                      // "The control digit (last digit) does not match."

let info = try Cnp.parse("2851231431232")           // throws a CnpError when invalid
info.sex                                            // .female
info.birthDate                                      // CnpDate, description "1985-12-31"
info.age                                            // 40 (on 2026-12-01)
info.county.name                                    // "București, Sectorul 3"
info.county.iso3166_2                               // "RO-B" (nil for code 70)

try Cnp.generate(GenerateOptions(sex: .female, minAge: 18, maxAge: 30))
try Cnp.generate(GenerateOptions(birthDate: CnpDate(iso: "2000-02-29"), county: "12"))
try Cnp.generate(GenerateOptions(resident: true, seed: 42))   // same result on every run

Every function takes an optional at: reference date (CnpDate(year:month:day:), CnpDate(iso:) or CnpDate(someFoundationDate)). It works like referenceDate in JavaScript, and defaults to today in the local time zone. CnpInfo, County and CnpDate are immutable values. Invalid options throw a GenerateError. To share one reproducible random stream across several calls, use Cnp.generate(options, using: &rng) with a SplitMix64. Cnp.counties, Cnp.county(code: "35"), Cnp.computeControlDigit("190010112001") (an Int?) and Cnp.controlKey work like in the other languages.

Swift Package Manager reads Package.swift from the repository root only. That is why Package.swift lives there and points to packages/swift, like composer.json does for PHP.

Try it in your terminal (Swift playground)

examples/swift is built by the root Package.swift as the cnp-playground executable. It has the same commands as the other terminal playgrounds:

swift run -c release cnp-playground                                           # interactive menu
swift run -c release cnp-playground validate 1900101120013
swift run -c release cnp-playground generate --sex=female --min-age=18 --max-age=30 --count=5 --seed=42
swift run -c release cnp-playground test vectors
swift run -c release cnp-playground test mine                                 # examples/swift/my_tests.txt
swift run -c release cnp-playground test stress --count=20000

The package tests run with swift test.

On Windows, add --build-system native to every swift build, swift run and swift test command (for example swift test --build-system native). Swift 6.4's default build system cannot compile with the newest Windows SDK (10.0.26100), which moved a C definition Swift relies on (_SH_DENYNO) into a new header. The older build system is not affected. On macOS and Linux no flag is needed.

How a CNP works

A CNP has 13 digits split into seven parts. For the exact algorithm in pseudocode (validation order, the resident century, age and the generator), see docs/algorithm.md.

 S   AA  LL  ZZ   JJ   NNN   C
 1   90  01  01   12   001   3
 |   |   |   |    |    |     +-- control digit
 |   |   |   |    |    +-------- sequence number (001-999)
 |   |   |   |    +------------- county code
 |   |   |   +------------------ day of birth
 |   |   +---------------------- month of birth
 |   +-------------------------- year of birth (last two digits)
 +------------------------------ sex + century

S: sex and century

S Sex Born
1 male 1900-1999
2 female 1900-1999
3 male 1800-1899
4 female 1800-1899
5 male 2000-2099
6 female 2000-2099
7 male foreign resident, century not encoded
8 female foreign resident, century not encoded

Odd digits are male and even digits are female. For Romanian citizens the digit also fixes the century, so AA = 85 with S = 2 can only mean 1985.

AA LL ZZ: birth date

Year (last two digits), month and day. The library checks the date against the real calendar. Remember the leap-year rule: every 4 years, except century years, except every 400 years. 2000 had a 29 February, but 1900 and 1800 did not, so 1000229... can never be valid.

JJ: county

The county (or Bucharest sector) where the person was born, or where they lived when the CNP was assigned.

Code Meaning
01-39 The counties, roughly in alphabetical order (Alba = 01, ..., Vrancea = 39)
40 București
41-46 București, sectors 1-6
47, 48 București, sectors 7 and 8: abolished on 4 August 1979, so only valid for people born before that date
51 Călărași
52 Giurgiu
70 Single national code used by the new civil-status IT system (SIIEASC) since 2024, whatever the county

Codes 00, 49, 50, 53-69 and 71-99 do not exist. Călărași and Giurgiu appear as 51 and 52 because those counties were created in 1981, after the original list was drawn up. The full table, with ISO 3166-2 codes, lives in spec/counties.json.

NNN: sequence number

A number from 001 to 999 that tells apart people of the same sex, born on the same day, with the same county code. The numbers are shared out between assignment points [2]. 000 is never assigned. For what happens when they run out, see When the sequence numbers run out.

C: the control digit (the "magic number")

The last digit is a checksum that catches typos. It is computed from the first 12 digits and the constant 279146358279:

  1. Multiply each of the first 12 digits by the digit at the same position in 279146358279.
  2. Add up the 12 products.
  3. Divide the sum by 11 and keep the remainder.
  4. If the remainder is 10, the control digit is 1. Otherwise the control digit is the remainder.

Worked example for 190010112001?:

CNP digits   1   9   0   0   1   0   1   1   2   0   0   1
Weights      2   7   9   1   4   6   3   5   8   2   7   9
Products     2  63   0   0   4   0   3   5  16   0   0   9   -> sum = 102

102 / 11 = 9, remainder 3   ->   control digit = 3   ->   1900101120013 (valid)

Change the sequence to 003 and the sum becomes 120. 120 / 11 leaves remainder 10, so the control digit is 1 (1900101120031).

Why 11? It is prime and none of the weights is a multiple of it. So one mistyped digit, or two neighbouring digits swapped, always changes the remainder. There is one blind spot: remainder 10 is folded into 1. An error that moves the remainder from 1 to 10, or from 10 to 1, therefore goes unnoticed. Treat the control digit as a typo detector, not a proof that a person exists.

Edge cases, and where the rules come from

Every rule below is backed by an official document listed under References.

Foreign residents (S = 7/8): the century is a guess

Foreigners who live in Romania get a CNP from the General Inspectorate for Immigration (IGI). The first digit only gives their sex (7 = male, 8 = female), and the next six digits are their birth date [3, 4, 5, 6]. No official text says which century the year belongs to.

The library takes the most recent year that does not put the birth date in the future. It says so openly with centuryInferred: true. For a foreign resident born in 1920, the code reads exactly like one born in 2020, and no software can tell the two apart. generate({ resident: true }) therefore only produces dates that read back unambiguously.

The 9 trap: NIF is not a CNP

Some validators accept 9 as the first digit "for foreigners". None of the Romanian identity or residence documents registered in PRADO mentions it, and neither does the legislation [1-6]. A 13-digit number starting with 9 is a NIF, a fiscal identification number that ANAF gives people who need to pay taxes in Romania but have no CNP. ANAF's own validation rules reject a NIF that doesn't start with 9 [9]. This library reports it as NIF_NOT_CNP, so you can tell your users what they typed instead of just "invalid".

County code 70 (since 2024)

Since OUG 12/2023, CNPs are generated automatically by the integrated civil-status IT system (SIIEASC) [1]. The Ministry of Internal Affairs announced that every CNP generated by this system uses the single code 70, whatever the place of birth. The system was rolled out between 8 May and 24 September 2024 [7].

The library accepts 70 for any birth date, not only 2024 onwards. A new CNP can be issued at any age, for example after a birth record is corrected or after a change of sex [2], and since 2024 it comes from the same system. When parsed, county is { code: '70', type: 'national', iso3166_2: null }.

When the sequence numbers run out (inferred, not confirmed)

What the official texts say:

  • NNN runs from 001 to 999 and is shared out between assignment points [2] [7].
  • OUG 97/2005, art. 6 (3), as amended by OUG 12/2023: CNPs are generated centrally by the General Directorate for Persons' Records (DGEP), as sole administrator. Art. 6 (4): when CNPs were not generated that way, or have been exhausted, DGEP generates supplementary CNPs at the request of the county services, the Bucharest service or the consular services [1].
  • Every CNP generated by the SIIEASC system uses the county code 70 [7].

What we infer from them, but no official text states:

  • Since births are now registered through SIIEASC, all newly generated CNPs share the code 70. The 999 limit therefore applies per day and per sex for the whole country, not per county.
  • No text says which county code the supplementary CNPs of art. 6 (4) carry. Explanations found online that 70 means "the numbers for that county and day ran out" are not backed by any of these sources: officially, 70 marks a CNP generated by SIIEASC.

None of this changes validation. A CNP can't show whether its sequence number was really assigned; only the population register knows that. So the library accepts any sequence from 001 to 999, and 70 for any birth date.

Bucharest sectors 7 and 8

From 4 August 1979, Decree 284/1979 reduced Bucharest from eight sectors to six: sector 8 merged into sector 1, sector 7 became sector 6, and so on [8]. Codes 47 and 48 are therefore accepted only for people born before that date.

A CNP can change

A new CNP is assigned when the birth record is corrected, the CNP was assigned by mistake, or the person changed sex [2]. So sex is the sex recorded when this CNP was assigned.

Generated CNPs and personal data

generate() produces structurally valid numbers, and any of them may belong to a real person. Use them for tests, demos and mock data only, never to impersonate anyone. Real CNPs are personal data under the GDPR: validate them, don't log them.

Project structure

romanian-cnp-validator/
+-- spec/
|   +-- counties.json        # source of truth for county codes (JJ)
|   +-- test-vectors.json    # shared valid/invalid cases: every package must pass them all
+-- scripts/
|   +-- generate.py          # builds each package's county table from spec/counties.json
|   +-- build-c.ps1          # Windows: build and test the C/C++ package with Visual Studio
|   +-- cross-check/         # proves every language gives identical results (see below)
+-- packages/
|   +-- javascript/          # npm package (ESM + CommonJS + CDN build, TypeScript types)
|   |   +-- dist/            # committed build, served by jsDelivr from GitHub
|   +-- python/              # PyPI package (typed, standard library only)
|   +-- php/                 # Composer package (src/, tests/, PHPUnit and PHPStan config)
|   +-- c/                   # C11 library + C++17 header, CMake, tests without dependencies
|   +-- csharp/              # NuGet package (src/, xUnit tests/)
|   +-- java/                # Maven Central package (Maven Wrapper, JUnit tests)
|   +-- go/                  # Go module (standard library only)
|   +-- rust/                # crates.io crate (no dependencies)
|   +-- swift/               # Swift package sources and XCTest tests (built by the root Package.swift)
+-- examples/
|   +-- javascript/
|   |   +-- playground.html  # open in a browser: try the local build and run tests
|   |   +-- test-vectors.js  # spec/test-vectors.json for the browser (generated)
|   +-- python/
|   |   +-- playground.py    # terminal playground: try the local source and run tests
|   |   +-- my_tests.txt     # your own test cases for the Python playground
|   +-- php/
|   |   +-- playground.php   # terminal playground for PHP, same commands as Python
|   |   +-- my_tests.txt     # your own test cases for the PHP playground
|   +-- c/
|   |   +-- playground.cpp   # terminal playground for C/C++, built by packages/c/CMakeLists.txt
|   |   +-- my_tests.txt     # your own test cases for the C/C++ playground
|   +-- csharp/
|   |   +-- Program.cs       # terminal playground for C#: dotnet run --project examples/csharp
|   |   +-- my_tests.txt     # your own test cases for the C# playground
|   +-- java/
|   |   +-- Playground.java  # terminal playground for Java, run directly by java (no javac step)
|   |   +-- my_tests.txt     # your own test cases for the Java playground
|   +-- go/
|   |   +-- main.go          # terminal playground for Go: go -C examples/go run .
|   |   +-- my_tests.txt     # your own test cases for the Go playground
|   +-- rust/
|   |   +-- main.rs          # terminal playground for Rust: cargo run --manifest-path examples/rust/Cargo.toml
|   |   +-- my_tests.txt     # your own test cases for the Rust playground
|   +-- swift/
|       +-- main.swift       # terminal playground for Swift: swift run cnp-playground
|       +-- my_tests.txt     # your own test cases for the Swift playground
+-- composer.json            # PHP package manifest (Packagist reads it from the repository root)
+-- nuget.config             # pins nuget.org as the .NET package source
+-- Package.swift            # Swift package manifest (SwiftPM reads it from the repository root)
+-- docs/
|   +-- algorithm.md         # the algorithm in pseudocode, step by step
|   +-- banner.svg           # the README banner
|   +-- social-preview.*     # the link preview image (repository settings and the demo page)
+-- site/index.html          # the live demo page (GitHub Pages)
+-- .claude/skills/           # maintenance skills for AI agents; their scripts also run on their own
+-- CLAUDE.md                # project rules for AI assistants
+-- .github/workflows/
|   +-- ci.yml               # tests every package on every push
|   +-- pages.yml            # builds the JavaScript bundle and publishes the live demo

Every package reads its county table from spec/counties.json and is tested against spec/test-vectors.json, so all languages agree on every edge case.

Cross-language check

The shared test vectors cover the known edge cases. To catch the unknown ones, scripts/cross-check runs every package against the same large input set and compares the results byte for byte:

  1. It builds about 60,000 CNP-like inputs. They cover every first digit with every county code, every month/day edge (29 February included), the 1979 sector boundary and residents around the reference date. They also include random valid numbers, each with one digit changed or two digits swapped, plus random and malformed strings.
  2. Each language generates 4,000 more CNPs, so every package also validates what the others generate.
  3. JavaScript, Python, PHP, C, C#, Java, Go, Rust and Swift validate everything. The error code, sex, birth date, age, residency, county, sequence and control digit must be identical in all of them.
  4. An independent re-implementation of the rules (oracle.py, written from this README rather than from the packages) checks the result. If every package shared the same mistake, it would still be caught.

All of this runs for three fixed reference dates on every push: 2026-12-01, 2000-02-29 (a leap day) and 1979-08-03 (the last day of sectors 7/8). To run it locally, build the C runner first, then:

bash scripts/cross-check/run.sh

If php or the C runner are not where the script expects them, pass their paths. For example, on Windows with the portable tools: PHP=tools/php/php.exe C_RUNNER=build/c/cnp_cross_check.exe bash scripts/cross-check/run.sh.

Contributing

Contributions are welcome: bug reports, edge cases you have met in the wild, new language packages.

Before opening a pull request:

  1. Rules need a source. If you change how a CNP is validated, link an official document (legislation, a ministry or agency page, PRADO). Blog posts and Wikipedia are fine for context, but not as proof.
  2. Edit the spec, not the generated files. County codes live in spec/counties.json. Run python scripts/generate.py (Python 3.11+, standard library only) and commit both.
  3. Add a test vector. New edge cases go in spec/test-vectors.json, so every language checks them.
  4. Run the package tests:
    • JavaScript: cd packages/javascript && npm ci && npm test. For a quick visual check, open the playground too.
    • Python: cd packages/python && pip install -e ".[dev]" && pytest && mypy. For a quick check, run the Python playground too.
    • PHP, from the repository root: composer install && composer test && composer analyse. For a quick check, run the PHP playground too.
    • C / C++, from the repository root: cmake -S packages/c -B build/c && cmake --build build/c && ctest --test-dir build/c. On Windows: powershell -ExecutionPolicy Bypass -File scripts\build-c.ps1. For a quick check, run the C/C++ playground too.
    • C#: dotnet test packages/csharp/tests/RomanianCnpValidator.Tests. For a quick check, run the C# playground too.
    • Java: cd packages/java && ./mvnw verify. For a quick check, run the Java playground too.
    • Go: go -C packages/go vet ./... && go -C packages/go test ./.... For a quick check, run the Go playground too.
    • Rust: cd packages/rust && cargo fmt --check && cargo clippy --all-targets -- -D warnings && cargo test. For a quick check, run the Rust playground too.
    • Swift, from the repository root: swift test (on Windows: swift test --build-system native). For a quick check, run the Swift playground too.
  5. Changed the JavaScript source? Rebuild and commit dist/: run npm run build. The build is committed so the GitHub CDN link works, and CI fails if it is stale.

Want to add a language? The full checklist is in .claude/skills/add-language. In short: copy the layout of an existing package, mirror its api tests one-to-one, add a generator target in scripts/generate.py, make it pass every test vector, add a runner to scripts/cross-check, and add a CI job.

Found a CNP that is real and valid but rejected here (or the other way round)? Open an issue with the reason, never the CNP itself. A made-up CNP with the same pattern is enough.

Checks and AI assistant skills (optional)

The repository ships a set of maintenance skills in .claude/skills/. If you work with an AI coding agent, it can use them to follow the project's rules instead of guessing them. Claude Code loads them automatically. Other agents can read them as plain Markdown: point the agent at the folder.

Skill What it does
verify-all Runs every check: the tests, linters and playgrounds of every package, generated files, README hygiene, parity between languages and the cross-language check
fix-across-languages Makes one rule change or bug fix in the spec, the tests and every package, then proves parity
add-language The complete checklist for a new language package
update-readme Keeps the documentation ASCII-only, sourced and with working links and executed examples
review-contribution Reviews a pull request the way the maintainer does
maintain-dependencies Updates dev dependencies and the CI matrix, and the yearly check of the official rules
triage-ci Diagnoses a failing GitHub Actions run and fixes it with as few pushes as possible
release Version bumps, tags and publishing to every registry

You don't need an AI agent to use them. The scripts are plain Python (standard library) and bash, so you can run them yourself before opening a pull request:

python .claude/skills/fix-across-languages/scripts/check_parity.py   # same rules and messages in every package
python .claude/skills/update-readme/scripts/check_readme.py          # ASCII, links, anchors, references
bash .claude/skills/verify-all/scripts/verify_all.sh --only python   # every check for one language (omit --only for all)

The checks skip a language whose toolchain is not installed and report it as SKIP, so you can run them with only the tools you have. AI help is welcome, but you are responsible for the change: every rule still needs an official source, and commits carry no AI co-author lines.

How it was built

Built with the help of Claude Code (Claude Opus 5.5). Every rule was checked against the official sources listed below, and every package passes the same test vectors and the cross-language check.

License

Code: MIT.

References

Official sources the rules are based on. All accessed December 2026.

1. OUG nr. 97/2005 on the records, domicile, residence and identity documents of Romanian citizens (republished, consolidated). Art. 6 defines the CNP, and art. 6 (1^1), added by OUG 12/2023, introduces generation through SIIEASC. Art. 6 (3) and (4), as amended by the same act, make DGEP the sole generator of CNPs, including supplementary ones when the available CNPs are exhausted. legislatie.just.ro

2. HG nr. 1375/2006, methodological norms for OUG 97/2005. Art. 14 gives the CNP structure (S, AALLZZ, JJ, NNN, C) and art. 15 the cases in which a new CNP is assigned. legislatie.just.ro

3. Council of the European Union, PRADO: Public Register of Authentic travel and identity Documents Online, Romanian residence documents ROU-HO-03001 to ROU-HO-03006. Each entry says the first digit is 7 or 8 for foreign residents and the next six digits are the birth date. consilium.europa.eu/prado

4. OUG nr. 194/2002 on the status of foreigners in Romania (republished, consolidated April 2026). Under art. 144^1, the General Inspectorate for Immigration assigns CNPs to foreigners. igi.mai.gov.ro

5. OUG nr. 102/2005 on the free movement of EU, EEA and Swiss citizens. Under art. 41, a CNP is assigned to EU citizens and their family members. igi.mai.gov.ro

6. HG nr. 1251/2006, methodological norms for Law 122/2006 on asylum. Annex 3 says the CNP's first digit is 7 or 8, depending on the holder's sex. mmuncii.gov.ro

7. Ministry of Internal Affairs (MAI), Precizări în ceea ce privește generarea codului numeric personal, 11 May 2024. Introduces the single county code 70 for CNPs generated by SIIEASC. mai.gov.ro

8. HG nr. 64/2011, methodology for civil status, Annex 80. Records the reorganisation of Bucharest's sectors from 4 August 1979 under Council of State Decree no. 284 of 31 July 1979. text of Annex 80

9. ANAF, XML structure of tax form D700 (March 2026). The validation rule for form 030 (registration of individuals without a CNP) rejects a fiscal code whose first digit isn't 9 ("nu e NIF"). static.anaf.ro