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-validationNote: 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
trueInvalid alpha2 country code:
Alpha2::create()->isValid('OO');Returns:
falseValid alpha2 country code:
$validator = new Alpha2();
$validator->isValid('DE')Returns:
trueInvalid alpha2 country code:
$validator = new Alpha2();
$validator->isValid('OO')Returns:
falseNote: validation case-insensitive.
Valid alpha3 country code:
Alpha3::create()->isValid('GBR')
Alpha3::create()->isValid('gbr')
Alpha3::create()->isValid('Gbr')Returns:
true
true
trueInvalid alpha3 country code:
Alpha3::create()->isValid('FOO');Returns:
falseValid alpha3 country code:
$validator = new Alpha3();
$validator->isValid('GBR')Returns:
trueInvalid alpha3 country code:
$validator = new Alpha3();
$validator->isValid('FOO')Returns:
falseValid country numeric code:
NumericCode::create()->isValid('646');Returns:
trueInvalid country numeric code:
NumericCode::create()->isValid('000');Returns:
falseValid country numeric code:
$validator = new NumericCode();
$validator->isValid('646')Returns:
trueInvalid country numeric code:
$validator = new NumericCode();
$validator->isValid('000')Returns:
falseNote: validation case-sensitive.
Valid country name:
Name::create()->isValid('Northern Mariana Islands');Returns:
trueInvalid country name:
Name::create()->isValid('foo');Returns:
falseValid country name:
$validator = new Name();
$validator->isValid('Northern Mariana Islands')Returns:
trueInvalid country name:
$validator = new Name();
$validator->isValid('foo')Returns:
falseNote: 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.