PHP code example of rocketfellows / iso-standard-3166-validation

1. Go to this page and download the library: Download rocketfellows/iso-standard-3166-validation 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/ */

    

rocketfellows / iso-standard-3166-validation example snippets


composer 

Alpha2::create()->isValid('DE');
Alpha2::create()->isValid('de');
Alpha2::create()->isValid('De');
Alpha2::create()->isValid('dE');

true
true
true
true

Alpha2::create()->isValid('OO');

false

$validator = new Alpha2();
$validator->isValid('DE')

true

$validator = new Alpha2();
$validator->isValid('OO')

false

Alpha3::create()->isValid('GBR')
Alpha3::create()->isValid('gbr')
Alpha3::create()->isValid('Gbr')

true
true
true

Alpha3::create()->isValid('FOO');

false

$validator = new Alpha3();
$validator->isValid('GBR')

true

$validator = new Alpha3();
$validator->isValid('FOO')

false

NumericCode::create()->isValid('646');

true

NumericCode::create()->isValid('000');

false

$validator = new NumericCode();
$validator->isValid('646')

true

$validator = new NumericCode();
$validator->isValid('000')

false

Name::create()->isValid('Northern Mariana Islands');

true

Name::create()->isValid('foo');

false

$validator = new Name();
$validator->isValid('Northern Mariana Islands')

true

$validator = new Name();
$validator->isValid('foo')

false

Alpha2Batch::create()->getInvalidValues(['DE', 'HH', 'BY', 'ZZ', 'GB',]);

['HH', 'ZZ']

$validator = new Alpha2Batch(Alpha2::create()); // possible inject other Alpha2 validator implementation
$validator->getInvalidValues(['DE', 'HH', 'BY', 'ZZ', 'GB',]);

['HH', 'ZZ']

Alpha3Batch::create()->getInvalidValues(['GBR', 'HH', 'RUS', 'ZZ', 'DEU',]);

['HH', 'ZZ']

$validator = new Alpha3Batch(Alpha3::create()); // possible inject other Alpha3 validator implementation
$validator->getInvalidValues(['GBR', 'HH', 'RUS', 'ZZ', 'DEU',]);

['HH', 'ZZ']

NumericCodeBatch::create()->getInvalidValues(['882', '000', '674', '111', '678',]);

['000', '111']

$validator = new NumericCodeBatch(NumericCode::create()); // possible inject other NumericCode validator implementation
$validator->getInvalidValues(['882', '000', '674', '111', '678',]);

['000', '111']

NameBatch::create()->getInvalidValues(['Samoa', 'foo', 'Sao Tome and Principe', 'bar', 'Saudi Arabia',]);

['foo', 'bar']

$validator = new NameBatch(Name::create()); // possible inject other Name validator implementation
$validator->getInvalidValues(['Samoa', 'foo', 'Sao Tome and Principe', 'bar', 'Saudi Arabia',]);

['foo', 'bar']