Validate and parse
validate(cnp, options), isValid(cnp, options) and parse(cnp, options).
Checks run in a fixed order, and the first failing check is reported.
The reference date is "today" for the checks: a birth date after it is rejected, and age is counted up to it.
What the functions return
Type a CNP above.
Control digit
computeControlDigit(first12) and CONTROL_KEY. Each of the first 12 digits is multiplied by
the matching digit of the key . The products are added, and the sum is divided by 11.
The remainder is the control digit, except that a remainder of 10 becomes 1 (HG 1375/2006, art. 14).
Generate
generate(options) returns a valid CNP for test data. Every option is optional.
Generated CNPs are synthetic: one may still belong to a real person by chance, so never use them as real identities.
The same call in code
Batch check
One CNP per line (spaces and empty lines are ignored). Uses validate and parse with the reference date above.
County codes (JJ)
COUNTIES and getCounty(code). Code 70 is the national code used by the SIIEASC system since 2024.
Sectors 47 and 48 existed only until 1979-08-03, so they are valid only for births up to that date.
getCounty("40")
| Code | Name | Type | ISO 3166-2 | Valid until |
|---|
Tests
Every language package must pass the same shared test vectors; here they run against this build. The stress test generates many CNPs with random options and checks that each one is valid and matches its options.
Use it in your code
npm install romanian-cnp-validator
import { validate, isValid, parse, generate, computeControlDigit, getCounty, COUNTIES, CONTROL_KEY }
from 'romanian-cnp-validator';
isValid('1900101120013'); // true
validate('1900101120014'); // { valid: false, error: 'INVALID_CONTROL_DIGIT', message: ... }
parse('1900101120013').county.name; // 'Cluj'
generate({ sex: 'female', county: '40', minAge: 18, maxAge: 30 });
In a page without a build step:
<script src="https://cdn.jsdelivr.net/npm/romanian-cnp-validator@1/dist/cnp.min.js"></script>
<script>
const { isValid } = window.RomanianCNP;
</script>
The rules, edge cases and their official sources are explained in the README.