This component consist of several country code validators. Validated country code formats:
- alpha2
- alpha3
- full name
- numeric code
It also can validate batch country code values and returns array of invalid given codes (or full name).
composer require rocketfellows/iso-standard-3166-validation
Note: validation case-insensitive.
Valid alpha2 country code:
Alpha2::create()->isValid('DE');
Alpha2::create()->isValid('de');
Alpha2::create()->isValid('De');
Alpha2::create()->isValid('dE');
Returns:
true
true
true
true
Invalid alpha2 country code:
Alpha2::create()->isValid('OO');
Returns:
false
Valid alpha2 country code:
$validator = new Alpha2();
$validator->isValid('DE')
Returns:
true
Invalid alpha2 country code:
$validator = new Alpha2();
$validator->isValid('OO')
Returns:
false
Note: validation case-insensitive.
Valid alpha3 country code:
Alpha3::create()->isValid('GBR')
Alpha3::create()->isValid('gbr')
Alpha3::create()->isValid('Gbr')
Returns:
true
true
true
Invalid alpha3 country code:
Alpha3::create()->isValid('FOO');
Returns:
false
Valid alpha3 country code:
$validator = new Alpha3();
$validator->isValid('GBR')
Returns:
true
Invalid alpha3 country code:
$validator = new Alpha3();
$validator->isValid('FOO')
Returns:
false
Valid country numeric code:
NumericCode::create()->isValid('646');
Returns:
true
Invalid country numeric code:
NumericCode::create()->isValid('000');
Returns:
false
Valid country numeric code:
$validator = new NumericCode();
$validator->isValid('646')
Returns:
true
Invalid country numeric code:
$validator = new NumericCode();
$validator->isValid('000')
Returns:
false
Note: validation case-sensitive.
Valid country name:
Name::create()->isValid('Northern Mariana Islands');
Returns:
true
Invalid country name:
Name::create()->isValid('foo');
Returns:
false
Valid country name:
$validator = new Name();
$validator->isValid('Northern Mariana Islands')
Returns:
true
Invalid country name:
$validator = new Name();
$validator->isValid('foo')
Returns:
false
Note: validation case-insensitive.
Validation:
Alpha2Batch::create()->getInvalidValues(['DE', 'HH', 'BY', 'ZZ', 'GB',]);
Returns:
['HH', 'ZZ']
Validation:
$validator = new Alpha2Batch(Alpha2::create()); // possible inject other Alpha2 validator implementation
$validator->getInvalidValues(['DE', 'HH', 'BY', 'ZZ', 'GB',]);
Returns:
['HH', 'ZZ']
Note: validation case-insensitive.
Validation:
Alpha3Batch::create()->getInvalidValues(['GBR', 'HH', 'RUS', 'ZZ', 'DEU',]);
Returns:
['HH', 'ZZ']
Validation:
$validator = new Alpha3Batch(Alpha3::create()); // possible inject other Alpha3 validator implementation
$validator->getInvalidValues(['GBR', 'HH', 'RUS', 'ZZ', 'DEU',]);
Returns:
['HH', 'ZZ']
Validation:
NumericCodeBatch::create()->getInvalidValues(['882', '000', '674', '111', '678',]);
Returns:
['000', '111']
Validation:
$validator = new NumericCodeBatch(NumericCode::create()); // possible inject other NumericCode validator implementation
$validator->getInvalidValues(['882', '000', '674', '111', '678',]);
Returns:
['000', '111']
Note: validation case-sensitive.
Validation:
NameBatch::create()->getInvalidValues(['Samoa', 'foo', 'Sao Tome and Principe', 'bar', 'Saudi Arabia',]);
Returns:
['foo', 'bar']
Validation:
$validator = new NameBatch(Name::create()); // possible inject other Name validator implementation
$validator->getInvalidValues(['Samoa', 'foo', 'Sao Tome and Principe', 'bar', 'Saudi Arabia',]);
Returns:
['foo', 'bar']
Welcome to pull requests. If there is a major changes, first please open an issue for discussion.
Please make sure to update tests as appropriate.