PHP code example of developingw / gov-validation-ua

1. Go to this page and download the library: Download developingw/gov-validation-ua 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/ */

    

developingw / gov-validation-ua example snippets




use DevelopingW\govValidationUA\PersonalTaxID;

$code = '3184710691';

try {
    /** @var PersonalTaxID $result */
    $result = PersonalTaxID::parse($code);

    if (PersonalTaxID::STATUS_VALID == $result->getStatus()) {
        echo 'Code valid:' . PersonalTaxID::parse($code)->getCode() . "\n";

        if (PersonalTaxID::SEX_FEMALE === $result->getSex()) {
            echo 'Woman' . "\n";
        } else {
            echo 'Man' . "\n";
        }

        echo 'Date of Birth: ' . $result->getYear() . '-' . $result->getMonth() . '-' . $result->getDay() . "\n";
        echo $result->getDateOfBirth() . "\n";
        
        echo 'Age person: ' . $result->getAge() . "\n";
    } else {
        echo 'Code invalid:' . $code . "\n";
    }

    print_r($result);
} catch (\Exception $e) {
    echo $e->getMessage()."\n";
}


Code valid:3184710691
Man
Date of Birth: 1987-03-12
1987-03-12
Age person: 36
DevelopingW\govValidationUA\PersonalTaxID Object
(
    [code:protected] => 3184710691
    [sex:protected] => M
    [control:protected] => 1
    [day:protected] => 12
    [month:protected] => 03
    [year:protected] => 1987
    [status:protected] => 1
)




use DevelopingW\govValidationUA\PersonalTaxID;

$code = '3184710692';

try {
    /** @var PersonalTaxID $result */
    $result = PersonalTaxID::parse($code);

    if (PersonalTaxID::STATUS_VALID == $result->getStatus()) {
        echo 'Code valid:' . $result->getCode() . "\n";

        if (PersonalTaxID::SEX_FEMALE === $result->getSex()) {
            echo 'Woman' . "\n";
        } else {
            echo 'Man' . "\n";
        }

        echo 'Date of Birth: ' . $result->getYear() . '-' . $result->getMonth() . '-' . $result->getDay() . "\n";
    } else {
        echo 'Code invalid:' . $code . "\n";
    }

    print_r($result);
} catch (\Exception $e) {
    echo $e->getMessage()."\n";
}

Code invalid:3184710692
DevelopingW\govValidationUA\PersonalTaxID Object
(
    [code:protected] => 3184710692
    [sex:protected] => M
    [control:protected] => 1
    [day:protected] => 12
    [month:protected] => 03
    [year:protected] => 1987
    [status:protected] => 
)



use DevelopingW\govValidationUA\LegalEntityTaxID;

if (LegalEntityTaxID::STATUS_VALID === LegalEntityTaxID::parse("40870076")->getStatus()) {
    echo 'ЄДРПОУ, Код, валідний!' . "\n";
} else {
    echo 'ЄДРПОУ, Код, невалідний!' . "\n";
}

'ЄДРПОУ, Код, невалідний!'



use DevelopingW\govValidationUA\BankCodeID;

if (BankCodeID::parse("320649")->getStatus()) {
    echo 'МФО валідний' . "\n";
}

'МФО валідний'



use DevelopingW\govValidationUA\CheckBarcodeID;

$result = CheckBarcodeID::parse('4823063112680');
if ($result->getStatus()) {
    print_r($result);
}

$result = CheckBarcodeID::parse('4823063125574');
if ($result->getStatus()) {
    print_r($result);
}

$result = CheckBarcodeID::parse('40345208');
if ($result->getStatus()) {
    print_r($result);
}

$result = CheckBarcodeID::parse('041689300494');
if ($result->getStatus()) {
    print_r($result);
}

$result = CheckBarcodeID::parse('5901234123457');
if ($result->getStatus()) {
    print_r($result);
}

DevelopingW\govValidationUA\CheckBarcodeID Object
(
    [code:protected] => 4823063112680
    [codeWithoutControl:protected] => 482306311268
    [control:protected] => 0
    [status:protected] => 1
    [standard:protected] => EAN-13
)
DevelopingW\govValidationUA\CheckBarcodeID Object
(
    [code:protected] => 4823063125574
    [codeWithoutControl:protected] => 482306312557
    [control:protected] => 4
    [status:protected] => 1
    [standard:protected] => EAN-13
)
DevelopingW\govValidationUA\CheckBarcodeID Object
(
    [code:protected] => 40345208
    [codeWithoutControl:protected] => 4034520
    [control:protected] => 8
    [status:protected] => 1
    [standard:protected] => EAN-8
)
DevelopingW\govValidationUA\CheckBarcodeID Object
(
    [code:protected] => 041689300494
    [codeWithoutControl:protected] => 04168930049
    [control:protected] => 4
    [status:protected] => 1
    [standard:protected] => UPC-12
)
DevelopingW\govValidationUA\CheckBarcodeID Object
(
    [code:protected] => 5901234123457
    [codeWithoutControl:protected] => 590123412345
    [control:protected] => 7
    [status:protected] => 1
    [standard:protected] => EAN-13
)