PHPackages                             designbycode/south-african-id-validator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. designbycode/south-african-id-validator

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

designbycode/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.

v2.0.2(1y ago)0661[1 PRs](https://github.com/designbycode/south-african-id-validator/pulls)MITPHPPHP ^8.1|^8.2|^8.3

Since Jun 19Pushed 1y agoCompare

[ Source](https://github.com/designbycode/south-african-id-validator)[ Packagist](https://packagist.org/packages/designbycode/south-african-id-validator)[ Docs](https://github.com/designbycode/south-african-id-validator)[ GitHub Sponsors](https://github.com/designbycode)[ RSS](/packages/designbycode-south-african-id-validator/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (5)Dependencies (5)Versions (7)Used By (0)

South African ID Validator
==========================

[](#south-african-id-validator)

[![Latest Version on Packagist](https://camo.githubusercontent.com/9ceb135c5fd995bcb199e395cf7d8694b9f6724bee885910e41616d30b443cfc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64657369676e6279636f64652f736f7574682d6166726963616e2d69642d76616c696461746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/designbycode/south-african-id-validator)[![Tests](https://camo.githubusercontent.com/2a6af399eb03cbf99845f37084eb13e64caecc0644f69faaed29491980c7efcd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f64657369676e6279636f64652f736f7574682d6166726963616e2d69642d76616c696461746f722f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/designbycode/south-african-id-validator/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/32eb211b4da6cc55a80d50e831ea36b44670625dcd1d7797047e152724a5424f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f64657369676e6279636f64652f736f7574682d6166726963616e2d69642d76616c696461746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/designbycode/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
------------

[](#installation)

You can install the package via composer:

```
composer require designbycode/south-african-id-validator
```

Usage
-----

[](#usage)

### Instantiation

[](#instantiation)

To use the South African ID Validator, create an instance of the `SouthAfricanIdValidator` class:

```
$validator = new SouthAfricanIdValidator();
```

### Validation

[](#validation)

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';
}
```

### Parsing

[](#parsing)

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
)

```

### Gender Determination

[](#gender-determination)

To determine the gender of the individual, use the `isMale` or `isFemale` methods:

```
$idNumber = '9404260051081';
if ($validator->isMale($idNumber)) {
    echo 'Male';
} else {
    echo 'Female';
}
```

### Citizenship Determination

[](#citizenship-determination)

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';
}
```

**Methods**
-----------

[](#methods)

### `isValid(mixed $idNumber): bool`

[](#isvalidmixed-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`

[](#islength13mixed-idnumber-bool)

Checks if the ID number has a length of 13 digits.

### `isNumber(mixed $idNumber): bool`

[](#isnumbermixed-idnumber-bool)

Checks if the ID number is numeric.

### `passesLuhnCheck(mixed $idNumber): bool`

[](#passesluhncheckmixed-idnumber-bool)

Validates the ID number using the Luhn Algorithm.

### `isMale(mixed $idNumber): bool`

[](#ismalemixed-idnumber-bool)

Determines if the ID number is for a male.

### `isFemale(mixed $idNumber): bool`

[](#isfemalemixed-idnumber-bool)

Determines if the ID number is for a female.

### `isSACitizen(mixed $idNumber): bool`

[](#issacitizenmixed-idnumber-bool)

Determines if the ID number is for a South African citizen.

### `isPermanentResident(mixed $idNumber): bool`

[](#ispermanentresidentmixed-idnumber-bool)

Determines if the ID number is for a permanent resident.

### `parse(mixed $idNumber): array`

[](#parsemixed-idnumber-array)

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 format `YYYY/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 Cases**
-------------

[](#use-cases)

### Validating ID numbers in a registration form

[](#validating-id-numbers-in-a-registration-form)

Use the `isValid` method to validate ID numbers in a registration form to ensure that only valid ID numbers are accepted.

### Extracting information from ID numbers

[](#extracting-information-from-id-numbers)

Use the `parse` method to extract information from ID numbers, such as birthdate, age, gender, and citizenship, to populate user profiles or perform analytics.

### Determining gender and citizenship

[](#determining-gender-and-citizenship)

Use the `isMale`, `isFemale`, `isSACitizen`, and `isPermanentResident` methods to determine the gender and

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Claude Myburgh](https://github.com/claudemyburgh)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 82.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~8 days

Total

5

Last Release

705d ago

Major Versions

v1.0.1 → v2.0.02024-06-21

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6057076?v=4)[Claude Myburgh](/maintainers/claudemyburgh)[@claudemyburgh](https://github.com/claudemyburgh)

---

Top Contributors

[![claudemyburgh](https://avatars.githubusercontent.com/u/6057076?v=4)](https://github.com/claudemyburgh "claudemyburgh (14 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

designbycodesouth-african-id-validator

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/designbycode-south-african-id-validator/health.svg)

```
[![Health](https://phpackages.com/badges/designbycode-south-african-id-validator/health.svg)](https://phpackages.com/packages/designbycode-south-african-id-validator)
```

###  Alternatives

[spatie/laravel-honeypot

Preventing spam submitted through forms

1.6k6.5M73](/packages/spatie-laravel-honeypot)[aporat/store-receipt-validator

PHP receipt validator for Apple App Store and Amazon Appstore

6513.9M11](/packages/aporat-store-receipt-validator)[statamic/cms

The Statamic CMS Core Package

4.8k3.5M920](/packages/statamic-cms)[waavi/sanitizer

Data sanitizer and Laravel 7 form requests with input sanitation.

433589.7k5](/packages/waavi-sanitizer)[elegantweb/sanitizer

Sanitization library for PHP and the Laravel framework.

1151.0M3](/packages/elegantweb-sanitizer)[arondeparon/laravel-request-sanitizer

An easy to use request sanitizer that allows you to sanitize your form data before validating it.

112157.8k3](/packages/arondeparon-laravel-request-sanitizer)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
