PHP libray providing various ISO codes validators
- International : IBAN, SWIFT/BIC, BBAN (RIB), Credit Card number, EAN13
- European : various VAT number formats
- France : Numéro de Sécurité Sociale / INSEE, SIREN, SIRET, Codes postaux, Clef Type 1/2 Norme B2
- US : Social Security number
- UK : National Insurance Number (NINO)
- Belgian structured communication ("communication structurée")
- Spain: NIF, NIE (Número de Identificación Fiscal/Extranjero) & CIF (Código de identificación fiscal)
- Zipcode for many countries: US, Canada, France, Netherlands, Portugal, Spain, etc.
Each code has its own validator. Each validator is illustrated by a unit test case.
IsoCodes is PHP 5.3 to 5.6 compatible & supports hhvm.
Continously inspecting results (phpdoc, phpmd, phpcc, etc.) available on Scrutinizer CI
PHP is required to be compiled with "--enable-bcmath" for some arbitrary precision mathematics checks (Iban & BBan ISO-codes).
Note that 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.
// Is this bank account number ok?
$isSwiftBic = SwiftBic::validate( 'CEDELULLXXX' );
// Will my letter reach the Labrador Islands ?
$isCanadian = ZipCode::validate( 'A0A 1A0', 'Canada');
// Worldwide money transfer, anyone ?
$isBankable = CreditCard::validate( '12345679123456' );
// Paying your taxes in Madrid?
$isTaxableInSpain = Nif::validate('A999999L');
// Does this book just exists?
$isPublished = Isbn10::validate('2-2110-4199-X')
$ git clone [email protected]:ronanguilloux/IsoCodes.git
Autoloading is PSR-0 friendly.
Create a composer.json file:
{
"require": {"ronanguilloux/isocodes": "@stable"}
}
Grab composer:
$ curl -s http://getcomposer.org/installer | php
Run install (will build the autoloading):
$ php composer.phar install
Install Soullivaneuh/IsoCodesValidator library to get IsoCodes working as Validator for Symfony and Silex.
$ 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: mak 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 +/- 750 tests & assertions, with separated valid & invalid entries sets. Tests values are mainly real data or documented examples from standards 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.
- GNU GPL v3
- You can find a copy of this software here: https://github.com/ronanguilloux/IsoCodes
The issue queue can be found at: https://github.com/ronanguilloux/IsoCodes/issues All contributors will be fully credited. Just sign up for a github account, create a fork and hack away at the codebase. Submit patches to: [email protected] Even one-off contributors will be fully credited (& probably blessed through three generations).
Contributors list: Many thanks to all!
Many thanks to IntelliJ/JetBrains/PhpStorm for having sponsored the IsoCode library development! Any contributor having an accepted PR may receive an Open Source License Key for PhpStorm IDE. Just ping Ronan Guilloux via email to get one.
- Various iso codes listed in http://www.credit-card.be/BankAccount/ValidationRules.htm
- ISBN13
- Add UK PostCode, UK Tax Code (http://www.braemoor.co.uk/software/vat.shtml)
- US phone number : /^(+\d)\s((\d{3})\s*)*\d{3}(-{0,1}|\s{0,1})\d{2}(-{0,1}|\s{0,1})\d{2}$/