Download the PHP package teknyo/lk-nic-validator-php without Composer
On this page you can find all versions of the php package teknyo/lk-nic-validator-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package lk-nic-validator-php
LK NIC Validator PHP
A comprehensive PHP package for validating Sri Lankan National Identity Card (NIC) numbers and extracting birth date and gender information.
Features
- Dual Format Support: Validates both old format (9 digits + V/X) and new format (12 digits)
- PHP 8.4+ Types: Full type definitions using PHP's native type system
- PSR-4 Autoloading: Compatible with modern PHP autoloading standards
- Comprehensive Validation: Format validation, logical birth date checks, and year range validation
- Detailed Information Extraction: Get birth date, gender, age, and normalized NIC format
- PHPUnit Tests: Comprehensive test suite included
Installation
Usage
Basic Validation
Extract Detailed Information
Helper Functions
Validation with Options
API Reference
Validation Methods
isSimpleValidNIC(string $nic): bool
Validates only the format without logical checks.
Parameters:
$nic: The NIC number to validate
Returns: true if format is valid, false otherwise
isFullValidNIC(string $nic): ValidationResult
Performs complete validation including format and logical checks.
Parameters:
$nic: The NIC number to validate
Returns: ValidationResult object with isValid and errorReason
validateNIC(string $nic, ?ValidationOptions $options = null): NICResult
Main validation function with optional expiry checking.
Parameters:
$nic: The NIC number to validate$options: Optional validation options
Returns: NICResult object with validation details
Information Extraction Methods
getNICDetails(string $nic): NICDetails
Extracts all available information from the NIC.
Returns: NICDetails object containing:
isValid: Whether the NIC is validnicNumber: Original NIC numbernormalizedNIC: NIC in new format (YYYYDDDNNNN)format: 'old', 'new', or 'invalid'errorReason: Error message if invalidbirthDate: Full birth date (DateTime object)birthYear: Birth year (4 digits)birthMonth: Birth month (1-12)birthDay: Birth day (1-31)dayOfYear: Day of year (1-366)gender: 'male' or 'female'age: Age in years
getNICGender(string $nic): Gender
Extracts gender from NIC.
getNICBirthYear(string $nic): ?int
Extracts birth year from NIC.
getNICDayOfYear(string $nic): ?int
Extracts day of year from NIC.
getNICBirthMonth(string $nic): ?int
Extracts birth month from NIC.
getNICBirthDay(string $nic): ?int
Extracts birth day from NIC.
convertOldToNewNIC(string $nic): ?string
Converts old format NIC to new format.
Type Definitions
NICFormat
Gender
NICResult
NICDetails
ValidationResult
ValidationOptions
NIC Format Details
Old Format (Pre-2016)
- 9 digits followed by V or X
- Example:
853456789V - First 2 digits: Year (assumed 19xx)
- Next 3 digits: Day of year (001-366 for males, 501-866 for females)
- Next 4 digits: Serial number
- Last letter: Check digit (V or X)
New Format (2016 onwards)
- 12 digits only
- Example:
198534567890 - First 4 digits: Full birth year
- Next 3 digits: Day of year (001-366 for males, 501-866 for females)
- Last 5 digits: Serial number
Gender Detection
- Old Format: Odd day code = Male, Even day code = Female
- New Format: Day code < 500 = Male, Day code >= 500 = Female
Examples
Laravel Integration
Symfony Integration
Running Tests
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Support
For issues or questions, please open an issue on the repository.