Logo Lanfrica

designbycode/south-african-id-validator

Record type:

software
Creator:
des
Host:
# South African ID Validator The South African ID Validator is a PHP class that validates and extracts information from South African ID numbers. It uses the Luhn Algorithm to validate the ID number and provides methods to determine the gender, citizenship, and birthdate of the individual. ## Installation You can install the package via composer: ```bash composer require designbycode/south-african-id-validator ``` ## Usage ### Instantiation To use the South African ID Validator, create an instance of the `SouthAfricanIdValidator` class: ```php $validator = new SouthAfricanIdValidator(); ``` ### Validation To validate an ID number, use the `isValid` method: ```php $idNumber = '9404260051081'; if ($validator->isValid($idNumber)) { echo 'ID number is valid'; } else { echo 'ID number is invalid'; } ``` ### Parsing To extract information from a valid ID number, use the `parse` method: ```php $idNumber = '9404260051081'; $parsedData = $validator->parse($idNumber); print_r($parsedData); ``` Output: ``` Array ( [valid] => 1 [birthday] => Arrya( 'default' => '1978-04-29', 'iso' => '1978-04-29', 'american' => '04/29/1978', 'european' => '04/29/1978', 'long' => 'April 29, 1978', ) [age] => 28 [gender] => Male [citizenship] => SA Citizen ) ``` ### Gender Determination To determine the gender of the individual, use the `isMale` or `isFemale` methods: ```php $idNumber = '9404260051081'; if ($validator->isMale($idNumber)) { echo 'Male'; } else { echo 'Female'; } ``` ### Citizenship Determination To determine the citizenship of the individual, use the `isSACitizen` or `isPermanentResident` methods: ```php $idNumber = '9404260051081'; if ($validator->isSACitizen($idNumber)) { echo 'SA Citizen'; } else { echo 'Permanent Resident'; } ``` **Methods** --------- ### `isValid(mixed $idNumber): bool` Validates the ID number using the Luhn Algorithm and checks if it has a length of 13 digits and is numeric. ### `isLength13(mixed $idNumber): bool` Checks if the ID number …

Licenses