oriceon / cnp
Romanian CNP Validator
Requires
- php: ^8.3
Requires (Dev)
- phpunit/phpunit: ^9.0
README
Validates Personal Identification Number (CNP) for Romanian citizens and residents.
Valid format:
|S|YY|MM|DD|CC|XXX|C|
where
|S| - Gender number for:
1 = Male, born between 1900 - 1999
2 = Female, born between 1900 - 1999
3 = Male, born between 1800 - 1899
4 = Female, born between 1800 - 1899
5 = Male, born between 2000 - 2099
6 = Female, born between 2000 - 2099
7 = Male resident (century does not apply)
8 = Female resident (century does not apply)
|YY| - year of birth - 00 - 99
|MM| - birth month - 01 - 12
|DD| - birthday - 01 - 28/29/30/31
|CC| - county code - for a valid value check CNP::COUNTY_CODE
|XXX|- the serial number assigned to the person - 000 - 999
|C| - check Digit
See https://ro.wikipedia.org/wiki/Cod_numeric_personal
Installation
You can install the package via composer:
composer require oriceon/cnp
Usage
use Oriceon\Cnp\Cnp; $cnpToValidate = 5110102441483; $cnp = new Cnp($cnpToValidate); if ($cnp->isValid()) { // extract info from CNP echo 'CNP ' . $cnpToValidate . ' - is valid' . PHP_EOL; echo 'Birth Date: ' . $cnp->getBirthDateFromCNP('Y/m/d') . ' (' . $cnp->getAgeInYears() . ' years) ' . PHP_EOL; echo 'Birthplace: ' . $cnp->getBirthCountyFromCNP() . PHP_EOL; echo 'Gender: ' . $cnp->getGenderFromCNP('male', 'female') . PHP_EOL; echo 'Person is ' . ($cnp->isPersonMajor() ? '' : 'not') . ' major' . PHP_EOL; echo 'Person have an Identity Card ' . ($cnp->hasIdentityCard() ? 'YES' : 'NO') . PHP_EOL; echo 'Person is resident ' . ($cnp->isResident() ? 'YES' : 'NO') . PHP_EOL; } else { echo 'CNP ' . $cnpToValidate . ' is invalid' . PHP_EOL; } // or call static echo 'CNP ' . $cnpToValidate . ' is ' . (Cnp::validate($cnpToValidate) ? 'valid' : 'invalid');
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email oriceon@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.