rocketfellows / iso-standard-3166-validation
Requires
- php: >=7.4
- arslanimamutdinov/iso-standard-3166: ^1.0
Requires (Dev)
- phpstan/phpstan: ^0.12.90
- phpunit/phpunit: ^8.5
- squizlabs/php_codesniffer: 3.6.2
This package is not auto-updated.
Last update: 2024-11-01 00:59:28 UTC
README
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).
Installation
composer require rocketfellows/iso-standard-3166-validation
Validate alpha2 code usage example
Note: validation case-insensitive.
Static usage
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
New instance creation usage
Valid alpha2 country code:
$validator = new Alpha2(); $validator->isValid('DE')
Returns:
true
Invalid alpha2 country code:
$validator = new Alpha2(); $validator->isValid('OO')
Returns:
false
Validate alpha3 code usage example
Note: validation case-insensitive.
Static usage
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
New instance creation usage
Valid alpha3 country code:
$validator = new Alpha3(); $validator->isValid('GBR')
Returns:
true
Invalid alpha3 country code:
$validator = new Alpha3(); $validator->isValid('FOO')
Returns:
false
Validate numeric code usage example
Static usage
Valid country numeric code:
NumericCode::create()->isValid('646');
Returns:
true
Invalid country numeric code:
NumericCode::create()->isValid('000');
Returns:
false
New instance creation usage
Valid country numeric code:
$validator = new NumericCode(); $validator->isValid('646')
Returns:
true
Invalid country numeric code:
$validator = new NumericCode(); $validator->isValid('000')
Returns:
false
Validate country name usage example
Note: validation case-sensitive.
Static usage
Valid country name:
Name::create()->isValid('Northern Mariana Islands');
Returns:
true
Invalid country name:
Name::create()->isValid('foo');
Returns:
false
New instance creation usage
Valid country name:
$validator = new Name(); $validator->isValid('Northern Mariana Islands')
Returns:
true
Invalid country name:
$validator = new Name(); $validator->isValid('foo')
Returns:
false
Validate alpha2 batch codes usage example
Note: validation case-insensitive.
Static usage
Validation:
Alpha2Batch::create()->getInvalidValues(['DE', 'HH', 'BY', 'ZZ', 'GB',]);
Returns:
['HH', 'ZZ']
New instance creation usage
Validation:
$validator = new Alpha2Batch(Alpha2::create()); // possible inject other Alpha2 validator implementation $validator->getInvalidValues(['DE', 'HH', 'BY', 'ZZ', 'GB',]);
Returns:
['HH', 'ZZ']
Validate alpha3 batch codes usage example
Note: validation case-insensitive.
Static usage
Validation:
Alpha3Batch::create()->getInvalidValues(['GBR', 'HH', 'RUS', 'ZZ', 'DEU',]);
Returns:
['HH', 'ZZ']
New instance creation usage
Validation:
$validator = new Alpha3Batch(Alpha3::create()); // possible inject other Alpha3 validator implementation $validator->getInvalidValues(['GBR', 'HH', 'RUS', 'ZZ', 'DEU',]);
Returns:
['HH', 'ZZ']
Validate numeric codes batch usage example
Static usage
Validation:
NumericCodeBatch::create()->getInvalidValues(['882', '000', '674', '111', '678',]);
Returns:
['000', '111']
New instance creation usage
Validation:
$validator = new NumericCodeBatch(NumericCode::create()); // possible inject other NumericCode validator implementation $validator->getInvalidValues(['882', '000', '674', '111', '678',]);
Returns:
['000', '111']
Validate country names batch usage example
Note: validation case-sensitive.
Static usage
Validation:
NameBatch::create()->getInvalidValues(['Samoa', 'foo', 'Sao Tome and Principe', 'bar', 'Saudi Arabia',]);
Returns:
['foo', 'bar']
New instance creation usage
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']
Contributing
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.