PHP code example of chaoswey / taiwan-id-validator

1. Go to this page and download the library: Download chaoswey/taiwan-id-validator 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/ */

    

chaoswey / taiwan-id-validator example snippets


use Chaoswey\TaiwanIdValidator\Facades\TaiwanIdValidator;

TaiwanIdValidator::isBan('04595257');
TaiwanIdValidator::isBan('04595252', ['applyOldRules' => true]); // 舊版演算法

// IdCard 基礎用法
TaiwanIdValidator::isIdCardNumber('A123456789');
TaiwanIdValidator::isIdCardNumber('A800000014', [
    'nationalId' => false,
    'uiNumber' => [
        'oldFormat' => false,
        'newFormat' => [
            'foreignOrStateless' => true,
            'statelessResident' => false,
            'hkMacaoResident' => false,
            'mainlandChinaResident' => false,
        ],
    ],
]);
TaiwanIdValidator::isMobileBarcode('/AAA33AA');

// 更複雜的 IdCard 組合
TaiwanIdValidator::isIdCardNumber('AA00000009', ['scope' => 'resident-original']); // 僅舊式統一證號
TaiwanIdValidator::isIdCardNumber('A870000015', [
    'scope' => 'resident-new',
    'nationalId' => false,
    'uiNumber' => [
        'oldFormat' => false,
        'newFormat' => [
            'enabled' => true,
            'categories' => [
                'foreignOrStateless' => false,
                'statelessResident' => true,
                'hkMacaoResident' => false,
                'mainlandChinaResident' => false,
            ],
        ],
    ],
]);
TaiwanIdValidator::isIdCardNumber('A880000018', [
    'scope' => ['resident-new'],
    'uiNumber' => [
        'oldFormat' => false,
        'newFormat' => [
            'categories' => [
                'foreignOrStateless' => false,
                'statelessResident' => false,
                'hkMacaoResident' => true,
                'mainlandChinaResident' => false,
            ],
        ],
    ],
]);
TaiwanIdValidator::isIdCardNumber('A123456789', [
    'scope' => 'citizen|resident-original', // 同時允許某範圍
    'uiNumber' => ['newFormat' => false],
]);

TaiwanIdValidator::isDonationCode('10001');
TaiwanIdValidator::isCitizenDigitalCertificate('AB12345678901234');
TaiwanIdValidator::isCreditCardNumberValid('5105105105105100', ['checkIssuerRegexes' => true]);

use Chaoswey\TaiwanIdValidator\TaiwanIdValidator;

$validator = new TaiwanIdValidator();
$validator->isBan('12345675');
$validator->isIdCardNumber('AA00000009', ['scope' => 'resident-original']);
$validator->isIdCardNumber('A800000014', [
    'nationalId' => false,
    'uiNumber' => [
        'oldFormat' => false,
        'newFormat' => [
            'categories' => [
                'foreignOrStateless' => true,
                'statelessResident' => false,
                'hkMacaoResident' => false,
                'mainlandChinaResident' => false,
            ],
        ],
    ],
]);
$validator->isMobileBarcode('/+.-++..');

TaiwanIdValidator::isIdCardNumber('A800000014', [
    'nationalId' => false,
    'uiNumber' => [
        'oldFormat' => false,
        'newFormat' => [
            'enabled' => true,
            'categories' => [
                'foreignOrStateless' => true,
                'statelessResident' => false,
                'hkMacaoResident' => false,
                'mainlandChinaResident' => false,
            ],
        ],
    ],
]);

use Chaoswey\TaiwanIdValidator\Factories\ValidatorFactory;
use Chaoswey\TaiwanIdValidator\TaiwanIdValidator;

$factory = new ValidatorFactory([
    'custom_ban' => App\Validators\MyBanValidator::class,
]);

$validator = new TaiwanIdValidator($factory);