PHP library - Validators for standards from ISO, International Finance, Public Administrations, GS1, Manufacturing Industry, Phone numbers & Zipcodes for many countries
PHP library - Validators for standards from ISO, International Finance, Public Administrations, GS1, Book Industry, Phone numbers & Zipcodes for many countries
// Sending letters to the Labrador Islands ?
$isCanadian = ZipCode::validate('A0A 1A0', 'CA');
// Checking out your e-commerce shopping cart?
$isBankable = CreditCard::validate('12345679123456');
// Transferring money worldwide?
$isSwiftBic = SwiftBic::validate('CEDELULLXXX');
// Paying your taxes in Madrid?
$isTaxableInSpain = Nif::validate('A999999L');
// Receiving containers from Port of Shanghai?
$isShippingContainerCode = Sscc::validate('806141411234567896');
// Publishing books?
$isPublished = Isbn::validate('2-2110-4199-X')
// Trading items with GTIN barcodes in GS1 system?
$isBarcode = Ean13::validate('4719512002889')
// Calling phone numbers in Palo Alto?
$isPhonable = PhoneNumber::validate('+1-650-798-2800', 'US')
// Buying Apple stocks?
$isISIN = Isin::validate('US0378331005'); // Apple Inc. (AAPL)
// Trading Apple products?
$isCUSIP = Cusip::validate('037833100'); // Apple Inc. (AAPL)
// Checking your iPhone device is valid?
$isDevice = Imei::validate('352066060926230');
// Selling your Honda Civic?
$isVin = VinNA::validate('1HGBH41JXMN109186');
bcmath
PHP extension)bcmath
PHP extension)Each code has its own validator.
Each validator is illustrated by a unit test case.
IsoCodes is compatible with all versions of PHP that are actively supported by the PHP project.
Continously inspecting results (phpdoc, phpmd, phpcc, etc.) available on Scrutinizer CI
For IBAN & BBAN ISO-codes, PHP is required to be compiled with “–enable-bcmath” for arbitrary precision mathematic checks.
Usually, you already have bcmath
bundled in your PHP version, since many common PHP packages (php-cli
, php-fpm
, php5-cgi
, libapache2-mod-php5
, etc.) in stable GNU/Linux distribution releases (such as Debian) are listed as having bcmath
built in to them, as an included module.
$ git clone [email protected]:ronanguilloux/IsoCodes.git
Autoloading is PSR-0 friendly.
Require the latest version of ronanguilloux/isocodes
with Composer
$ composer require ronanguilloux/isocodes
Install Soullivaneuh/IsoCodesValidator
to get IsoCodes working as Validator for Symfony and Silex.
Install gourmet/validation
to get IsoCodes working with CakePHP 3 as a validator.
Install pixelpeter/laravel5-isocodes-validation
to get IsoCodes working with Laravel 5 as a validator.
$ phpunit --testdox --coverage-text
For development & contribution purpose only,
a Makefile provides various tools to check your code style, quality & test coverage:
Usual tasks:
To initialize vendors: make
To check code quality: make quality
To run tests suite: make tests
To fix code style: make cs-fix
Other specific tasks:
To evaluate code coverage: make codecoverage
To run a simple continuous tests server: make continuous
To dry-fix code style issues: make dry-fix
To evaluate code quality stats: make stats
To update vendors using Composer: make update
Isocodes quality plan is mainly based on phpunit: it runs 980+ unit tests,
with separated valid & invalid entry sets.
Test values are mainly real data or documented examples from standard documentation, and a few handmade values.
The composer.json
already includes these Php Quality Assurance Toolchain libraries:
Just run:
$ make stats -i
XML report outputs are then generated in a new ./build
folder
Code covering report built using Coveralls.io.
How-to generate such code coverage report using PHPUnit.
The issue queue can be found at: https://github.com/ronanguilloux/IsoCodes/issues.
See CONTRIBUTING.md.
Contributors list: Many thanks to all!
Many thanks to JetBrains PhpStorm for having sponsored the IsoCode library development from the very beginning! Any contributor having an accepted PR may receive an Open Source License Key for PhpStorm IDE. Just ping Ronan via email to get one.