MarjovanLier / SouthAfricanIDValidator

A sophisticated PHP package designed to validate South African ID numbers by checking both structural and contextual rules
MIT License
0 stars 1 forks source link

South African ID Validator

Table of Contents

Introduction

The SouthAfricanIDValidator PHP package is your comprehensive solution for validating South African ID numbers, crucial for any application processing or verifying South African identities. Validation of ID numbers is essential, as it ensures that IDs adhere to both specific structural and contextual standards outlined in South African identity documentation. This package stands out for its ease of use, high accuracy, and thorough validation checks, including structure and format validation, birth date verification, gender, citizenship status, and race indicator digits, and applying the Luhn algorithm for checksum digit validation.

Badges

Packagist Version Packagist Downloads Packagist License PHP from Packagist Latest Stable Version PHPStan Enabled Phan Enabled Psalm Enabled codecov Qodana

Features

System Requirements

Installation

Getting Started

To begin using the SouthAfricanIDValidator in your project, follow these simple steps:

  1. Install via Composer - Run the following command to install the package:

    composer require marjovanlier/southafricanidvalidator
  2. Basic Usage Example - After installation, you can start validating South African ID numbers with the following code snippet:

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

To integrate the SouthAfricanIDValidator into your project, install it via Composer:

composer require marjovanlier/southafricanidvalidator

Usage

To validate a South African ID number, instantiate the SouthAfricanIDValidator class and call the luhnIDValidate method:

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

The luhnIDValidate method returns true if the ID number is valid, false if it's invalid, and null if specific criteria aren't met (e.g., incorrect citizenship status digit).

Troubleshooting

Encountering issues? Here are solutions to some common problems:

For additional help or to report a new issue, please visit our GitHub issue tracker.

Testing

First, ensure you have all the necessary development dependencies installed by running composer install --dev. Then, run the following command to execute the unit tests included with the package:

composer tests

Contributing

We value your contributions to the SouthAfricanIDValidator package! Here's how you can help:

  1. Report Issues or Suggest Enhancements - Noticed a bug or have an idea to make the package better? Start by filing an issue on our GitHub repo. This lets us discuss possible changes before you start coding.

  2. Contribute Code - Fork the repo, then create a new branch for your work, adhering to our branching strategy guidelines. This keeps things organised and ensures consistency across contributions.

  3. Follow Our Coding Standards - Write clean, readable code that adheres to our coding standards. This makes it easier for everyone to understand and maintain.

  4. Write or Update Tests - Help ensure reliability by writing tests for new features or updating existing tests as needed.

  5. Submit a Pull Request - Finished making changes? Open a pull request against the main branch with a detailed explanation of what you did and why.

Your contributions are crucial to improving the SouthAfricanIDValidator package for everyone!

License Information

The SouthAfricanIDValidator is proudly open-sourced under the MIT Licence. This licence allows you to use, modify, distribute and contribute back to the package, both in private and commercial projects, but you must include the original copyright and license notice in any copy of the software. For full details about your rights and obligations, refer to the License File.

Release Notes

Stay updated by checking our GitHub Releases page.