### Install South African ID Validator via Composer Source: https://github.com/marjovanlier/southafricanidvalidator/blob/main/README.md This snippet shows the command to install the South African ID Validator package using Composer, a dependency manager for PHP. Ensure Composer is installed and accessible in your environment. ```bash composer require marjovanlier/southafricanidvalidator ``` -------------------------------- ### Run Unit Tests with Composer Source: https://github.com/marjovanlier/southafricanidvalidator/blob/main/README.md This command is used to execute the unit tests included in the South African ID validator package. Ensure development dependencies are installed first using `composer install --dev`. ```bash composer tests ``` -------------------------------- ### Validate South African ID Number using PHP Source: https://github.com/marjovanlier/southafricanidvalidator/blob/main/README.md This snippet demonstrates how to use the `luhnIDValidate` method from the `SouthAfricanIDValidator` class to validate a South African ID number. It shows how to handle the different return values (`true`, `false`, `null`) indicating the validity and specific issues with the ID number. ```php use MarjovanLier\SouthAfricanIDValidator\SouthAfricanIDValidator; $idNumber = 'Your South African ID number here'; $result = SouthAfricanIDValidator::luhnIDValidate($idNumber); if ($result) { echo 'The ID number is valid.'; } elseif (!$result) { echo 'The ID number is invalid.'; } else { echo 'The ID number does not meet specific constraints.'; } ``` -------------------------------- ### Convert Legacy to Modern South African ID (PHP) Source: https://context7.com/marjovanlier/southafricanidvalidator/llms.txt Converts legacy South African ID numbers to the modern format by updating the race indicator. It defaults to '8' but can accept '9' as an alternative for duplicate prevention. Invalid IDs or modern indicators return null. ```php use MarjovanLier\SouthAfricanIDValidator\SouthAfricanIDValidator; // Convert legacy ID (race indicator 0) to modern format (8) $legacyId = '8001015009087'; $modernId = SouthAfricanIDValidator::convertLegacyToModern($legacyId); var_dump($modernId); // string(13) "8001015009889" // Convert to alternative modern indicator (9) for duplicate prevention $alternativeId = SouthAfricanIDValidator::convertLegacyToModern($legacyId, 9); var_dump($alternativeId); // string(13) "8001015009988" // Already modern ID is returned as-is $alreadyModern = '8001015009889'; $result = SouthAfricanIDValidator::convertLegacyToModern($alreadyModern); var_dump($result); // string(13) "8001015009889" // Invalid ID returns null $invalidId = '1234567890123'; $result = SouthAfricanIDValidator::convertLegacyToModern($invalidId); var_dump($result); // NULL // Invalid modern indicator returns null $result = SouthAfricanIDValidator::convertLegacyToModern($legacyId, 7); var_dump($result); // NULL ``` -------------------------------- ### Validate South African ID Number in PHP Source: https://github.com/marjovanlier/southafricanidvalidator/blob/main/README.md This PHP code snippet demonstrates how to use the SouthAfricanIDValidator to validate a South African ID number. It includes instantiating the validator and calling the `luhnIDValidate` method, which returns true for valid IDs, false for invalid ones, and a specific message for format-related issues. ```php use MarjovanLier\SouthAfricanIDValidator\SouthAfricanIDValidator; // Instantiate the ID validator $validator = new SouthAfricanIDValidator(); // Validate a South African ID number $idNumber = 'Your South African ID number here'; $isValid = $validator->luhnIDValidate($idNumber); if ($isValid === true) { echo 'The ID number is valid.'; } elseif ($isValid === false) { echo 'The ID number is invalid.'; } else { echo 'The ID number does not meet specific constraints.'; } ``` -------------------------------- ### Extract Info from SA ID Number (PHP) Source: https://context7.com/marjovanlier/southafricanidvalidator/llms.txt Extracts detailed information from a South African ID number, including date components, gender, citizenship status, and legacy race indicators. Returns an associative array with extracted data or null values for invalid IDs. Requires a valid ID number format. ```php use MarjovanLier\SouthAfricanIDValidator\SouthAfricanIDValidator; // Extract information from a valid ID $idNumber = '8001015009087'; $info = SouthAfricanIDValidator::extractInfo($idNumber); print_r($info); /* Array ( [valid] => 1 [date_components] => Array ( [year] => 80 [month] => 01 [day] => 01 ) [gender] => male [citizenship] => south_african_citizen [is_legacy] => 1 [race_indicator] => 8 ) */ // Invalid ID returns null values $invalidId = '1234567890123'; $info = SouthAfricanIDValidator::extractInfo($invalidId); print_r($info); /* Array ( [valid] => [date_components] => [gender] => [citizenship] => [is_legacy] => [race_indicator] => ) */ ``` -------------------------------- ### Batch Validate South African IDs (PHP) Source: https://context7.com/marjovanlier/southafricanidvalidator/llms.txt Validates multiple South African ID numbers efficiently in a single operation. It returns an array mapping valid IDs to '1' and invalid or skipped entries to an empty value. Non-string values in the input array are automatically skipped. ```php use MarjovanLier\SouthAfricanIDValidator\SouthAfricanIDValidator; $idNumbers = [ '8001015009087', // Valid citizen '8001014009083', // Valid female '1234567890123', // Invalid checksum '8001015039084', // Invalid citizenship '9513321234089', // Invalid date ]; $results = SouthAfricanIDValidator::batchValidate($idNumbers); print_r($results); /* Array ( [8001015009087] => 1 [8001014009083] => 1 [1234567890123] => [8001015039084] => [9513321234089] => ) */ // Non-string values are automatically skipped $mixedArray = [ '8001015009087', 123, null, '8001014009083', ]; $results = SouthAfricanIDValidator::batchValidate($mixedArray); print_r($results); /* Array ( [8001015009087] => 1 [8001014009083] => 1 ) */ ``` -------------------------------- ### Extract Date Components from SA ID (PHP) Source: https://context7.com/marjovanlier/southafricanidvalidator/llms.txt Retrieves the year, month, and day components from a South African ID number. This function parses the first six digits of the ID. It returns an associative array with date parts or NULL if the ID number is invalid or the date components cannot be parsed. ```php use MarjovanLier\SouthAfricanIDValidator\SouthAfricanIDValidator; $idNumber = '9506231234089'; $dateComponents = SouthAfricanIDValidator::extractDateComponents($idNumber); print_r($dateComponents); /* Array ( [year] => 95 [month] => 06 [day] => 23 ) */ // Invalid ID returns null $invalidId = '9513321234089'; $result = SouthAfricanIDValidator::extractDateComponents($invalidId); var_dump($result); // NULL ``` -------------------------------- ### Detect Duplicate South African IDs (PHP) Source: https://context7.com/marjovanlier/southafricanidvalidator/llms.txt Checks if two South African ID numbers would be considered duplicates by comparing their first 11 digits, which represent date of birth, gender, and citizenship. It returns true if the first 11 digits match, and false otherwise. Invalid IDs result in a false return value. ```php use MarjovanLier\SouthAfricanIDValidator\SouthAfricanIDValidator; // Two IDs with same date/sequence/citizenship but different race indicators $id1 = '8001015009087'; $id2 = '8001015009186'; $areDuplicates = SouthAfricanIDValidator::wouldBeDuplicates($id1, $id2); var_dump($areDuplicates); // bool(true) // IDs with different components $id3 = '8001015009087'; $id4 = '8001016009086'; $areDuplicates = SouthAfricanIDValidator::wouldBeDuplicates($id3, $id4); var_dump($areDuplicates); // bool(false) // Invalid IDs return false $invalidId = '12345'; $validId = '8001015009087'; $areDuplicates = SouthAfricanIDValidator::wouldBeDuplicates($invalidId, $validId); var_dump($areDuplicates); // bool(false) ``` -------------------------------- ### Extract Citizenship from South African ID (PHP) Source: https://context7.com/marjovanlier/southafricanidvalidator/llms.txt Determines the citizenship status from the 11th digit of a South African ID number. It returns 'south_african_citizen' for '0', 'permanent_resident' for '1', and 'refugee' for '2'. Invalid citizenship digits return null. ```php use MarjovanLier\SouthAfricanIDValidator\SouthAfricanIDValidator; // South African citizen (0) $citizenId = '8001015009087'; $citizenship = SouthAfricanIDValidator::extractCitizenship($citizenId); var_dump($citizenship); // string(22) "south_african_citizen" // Permanent resident (1) $residentId = '8001015019086'; $citizenship = SouthAfricanIDValidator::extractCitizenship($residentId); var_dump($citizenship); // string(19) "permanent_resident" // Refugee (2) $refugeeId = '8001015029085'; $citizenship = SouthAfricanIDValidator::extractCitizenship($refugeeId); var_dump($citizenship); // string(7) "refugee" // Invalid citizenship digit returns null $invalidId = '8001015039084'; $citizenship = SouthAfricanIDValidator::extractCitizenship($invalidId); var_dump($citizenship); // NULL ``` -------------------------------- ### Validate South African ID Number (PHP) Source: https://context7.com/marjovanlier/southafricanidvalidator/llms.txt Validates a South African ID number using the Luhn algorithm and performs full structural and contextual checks. It returns a boolean for valid/invalid IDs, or NULL for invalid citizenship digits. Accepts formatted input and checks for correct length. ```php use MarjovanLier\SouthAfricanIDValidator\SouthAfricanIDValidator; $validator = new SouthAfricanIDValidator(); // Valid South African citizen ID $validId = '8001015009087'; $result = $validator->luhnIDValidate($validId); var_dump($result); // bool(true) // Invalid checksum $invalidId = '8001015009088'; $result = $validator->luhnIDValidate($invalidId); var_dump($result); // bool(false) // Invalid citizenship digit (position 11 must be 0, 1, or 2) $invalidCitizenship = '8001015009387'; $result = $validator->luhnIDValidate($invalidCitizenship); var_dump($result); // NULL // Accepts formatted input $formattedId = '80-0101-5009-08-7'; $result = $validator->luhnIDValidate($formattedId); var_dump($result); // bool(true) // Invalid length $shortId = '123456'; $result = $validator->luhnIDValidate($shortId); var_dump($result); // bool(false) ``` -------------------------------- ### Detect Legacy South African ID Format (PHP) Source: https://context7.com/marjovanlier/southafricanidvalidator/llms.txt Checks if a South African ID number uses the legacy apartheid-era race indicator, which ranges from 0 to 7. It returns true for legacy IDs and false for modern IDs (race indicators 8 or 9). ```php use MarjovanLier\SouthAfricanIDValidator\SouthAfricanIDValidator; // Legacy ID with race indicator 0-7 $legacyId = '8001015009087'; $isLegacy = SouthAfricanIDValidator::isLegacyID($legacyId); var_dump($isLegacy); // bool(true) // Modern ID with race indicator 8 or 9 $modernId = '8001015009889'; $isLegacy = SouthAfricanIDValidator::isLegacyID($modernId); var_dump($isLegacy); // bool(false) ``` -------------------------------- ### Validate ID Date Component (PHP) Source: https://context7.com/marjovanlier/southafricanidvalidator/llms.txt Validates the date component (YYMMDD format) of a South African ID number. It correctly handles historical dates from the 1800s onwards and checks for valid day and month combinations. Returns false for invalid formats or non-existent dates. ```php use MarjovanLier\SouthAfricanIDValidator\SouthAfricanIDValidator; // Valid date - 1st January 1980 $validDate = '800101'; $isValid = SouthAfricanIDValidator::isValidIDDate($validDate); var_dump($isValid); // bool(true) // Valid historical date - 15th March 1896 $historicalDate = '960315'; $isValid = SouthAfricanIDValidator::isValidIDDate($historicalDate); var_dump($isValid); // bool(true) // Invalid date - 32nd January (no such date) $invalidDate = '800132'; $isValid = SouthAfricanIDValidator::isValidIDDate($invalidDate); var_dump($isValid); // bool(false) // Invalid date - February 30th $invalidFeb = '800230'; $isValid = SouthAfricanIDValidator::isValidIDDate($invalidFeb); var_dump($isValid); // bool(false) // Invalid format - too short $shortDate = '8001'; $isValid = SouthAfricanIDValidator::isValidIDDate($shortDate); var_dump($isValid); // bool(false) ``` -------------------------------- ### Extract Gender from South African ID (PHP) Source: https://context7.com/marjovanlier/southafricanidvalidator/llms.txt Determines the gender (male or female) from the sequence number portion (positions 7-10) of a South African ID number. It returns 'male' for sequences 5000-9999 and 'female' for 0000-4999. Invalid IDs return null. ```php use MarjovanLier\SouthAfricanIDValidator\SouthAfricanIDValidator; // Male ID (sequence 5000-9999) $maleId = '8001015009087'; $gender = SouthAfricanIDValidator::extractGender($maleId); var_dump($gender); // string(4) "male" // Female ID (sequence 0000-4999) $femaleId = '8001014009083'; $gender = SouthAfricanIDValidator::extractGender($femaleId); var_dump($gender); // string(6) "female" // Invalid ID returns null $invalidId = '12345'; $gender = SouthAfricanIDValidator::extractGender($invalidId); var_dump($gender); // NULL ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.