PHP code example of helip / niss

1. Go to this page and download the library: Download helip/niss library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

helip / niss example snippets




elip\NISS\Helpers\NISSValidatorHelper;
use Helip\NISS\Exception\InvalidNissExceptionInterface;
use Helip\NISS\NISS;

$rawNiss = '13820404235';

// --- Option 1: Simple validation (boolean result) ---
if (NISSValidatorHelper::isValid($rawNiss)) {
    echo "NISS is valid";
} else {
    echo "NISS is invalid";
}

// --- Option 2: Strict validation (with exceptions) ---
try {
    NISSValidatorHelper::assertValid($rawNiss); // throws on failure
    echo "NISS passed strict validation ✔️";
} catch (InvalidNissExceptionInterface $e) {
    echo "Validation error: " . $e->getMessage(); // Custom exception type
}

// Instantiates a Niss object
$niss = new NISS($rawNiss);
    
// Get infos
$birthdate = $niss->getBirthdate();
$gender = $niss->getGender()
$type = $niss->getType();
$formatted = $niss->getFormattedNiss();
// ...