rossn is a production-ready, permissively-licensed Go package for validating Romanian CNP (Personal Numeric Code) numbers.
It checks CNP structure, birth date, county, serial number, and official checksum.
Thoroughly tested against all official rules and edge cases.
- Validates CNP length, digits, date, county, serial (001–999), and checksum
- Full support for archival Bucharest codes 47/48 (historical), and for code 70 for foreign/stateless residents (S=7,8,9 only), as per cnp-spec and Wikipedia.
- Full support for SIIEASC JJ=70 (2024+) as per the official statement of the Romanian Ministry of Internal Affairs, May 2024
- 100% Go, no dependencies
- MIT licensed: Free for commercial and closed-source use
- Fast, robust, and tested
go get github.com/ac999/rossn
package main
import (
"fmt"
"github.com/ac99/rossn"
)
func main() {
err := rossn.Validate("1981214320015")
if err != nil {
fmt.Println("Invalid CNP:", err)
} else {
fmt.Println("Valid CNP!")
}
}
A CNP is 13 digits: SYYMMDDJJNNNC
S
: Gender and centuryYYMMDD
: Date of birth (with S determining the century)JJ
: County code (01–52, official list)NNN
: Serial number (001–999)C
: Control digit (checksum, see here)
All checks are performed according to the official Romanian government rules.
Run all tests with:
go test ./...
Or for detailed output:
go test -v
Pull requests and issue reports are welcome! Before submitting, make sure all tests pass and that new edge cases are covered by tests.
MIT License — see LICENSE