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.
You can install the package via composer:
composer require designbycode/south-african-id-validator
To use the South African ID Validator, create an instance of the SouthAfricanIdValidator
class:
$validator = new SouthAfricanIdValidator();
To validate an ID number, use the isValid
method:
$idNumber = '9404260051081';
if ($validator->isValid($idNumber)) {
echo 'ID number is valid';
} else {
echo 'ID number is invalid';
}
To extract information from a valid ID number, use the parse
method:
$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
)
To determine the gender of the individual, use the isMale
or isFemale
methods:
$idNumber = '9404260051081';
if ($validator->isMale($idNumber)) {
echo 'Male';
} else {
echo 'Female';
}
To determine the citizenship of the individual, use the isSACitizen
or isPermanentResident
methods:
$idNumber = '9404260051081';
if ($validator->isSACitizen($idNumber)) {
echo 'SA Citizen';
} else {
echo 'Permanent Resident';
}
Validates the ID number using the Luhn Algorithm and checks if it has a length of 13 digits and is numeric.
Checks if the ID number has a length of 13 digits.
Checks if the ID number is numeric.
Validates the ID number using the Luhn Algorithm.
Determines if the ID number is for a male.
Determines if the ID number is for a female.
Determines if the ID number is for a South African citizen.
Determines if the ID number is for a permanent resident.
Parses the ID number and returns an array with the following information:
valid
: A boolean indicating if the ID number is valid.birthday
: The birthdate in the formatYYYY/MM/DD
.age
: The age of the individual.gender
: The gender of the individual (Male or Female).citizenship
: The citizenship status of the individual (SA Citizen or Permanent Resident).
Use the isValid
method to validate ID numbers in a registration form to ensure that only valid ID numbers are accepted.
Use the parse
method to extract information from ID numbers, such as birthdate, age, gender, and citizenship, to populate user profiles or perform analytics.
Use the isMale
, isFemale
, isSACitizen
, and isPermanentResident
methods to determine the gender and
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.