PHP library - Validators for standards from ISO, International Finance, Public Administrations, GS1, Manufacturing Industry, Phone numbers & Zipcodes for many countries

Overview

IsoCodes

PHP library - Validators for standards from ISO, International Finance, Public Administrations, GS1, Book Industry, Phone numbers & Zipcodes for many countries

Usage

// 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');    

ISO Codes Validations available:

International Finance

  • IBAN (requires bcmath PHP extension)
  • SWIFT/BIC
  • BBAN (RIB, requires bcmath PHP extension)
  • Credit Card number
  • SEDOL (Stock Exchange codes)

Manufacturing Industries

  • ISBN - International Standard Book Number, both 10 & 13 digits
  • ISMN - International Standard Music Number
  • ISWC - International Standard Musical Work Code
  • IMEI - International Mobile Equipment Identity
  • VIN - Vehicle Identification Number – ISO 3779 & ISO 4030

Public Administrations

  • ISIN - International Securities Identification Number
  • Country-specific VAT / tax system: 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)
  • Belgium: Structured Ccommunication ("communication structurée")
  • Spain: NIF, NIE (Número de Identificación Fiscal/Extranjero) & CIF (Código de identificación fiscal)
  • Netherlands: Burgerservicenummer / Citizen Service Number (BSN)
  • Finland: HETU, Henkilötunnus (Finnish personal identity code)
  • Switzerland: Business Orgs UID (VAT) Number / Unternehmens-Identifikationsnummer

GS1 specific numbers/identifiers

  • GTIN - Global Trade Item Number: GTIN-8, GTIN-12, GTIN-13, GTIN-14
  • GLN - Global Location Number
  • SSCC - Serial Shipping Container Code
  • GRAI - Global Returnable Asset Identifier
  • GSRN - Global Service Relation Number
  • GDTI - Global Document Type Identifier
  • UDI - Unique Device Identification (the GTIN part of it)
  • Older/deprecated identifiers, now in GTIN: EAN-8, EAN-13, UCC-13, UPC-A, DUN-14, ITF-14

Miscellaneous

  • ZIP code validators for 175+ countries
  • Phone number validation for all countries/regions of the world

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, plus hhvm.

Build status

License Latest Stable Version Latest Unstable Version Build Status Scrutinizer Code Quality SensioLabsInsight Coverage Status Total Downloads Monthly Downloads Daily Downloads

Continously inspecting results (phpdoc, phpmd, phpcc, etc.) available on Scrutinizer CI

bcmath as an optional extension for certain validators

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.

Installing

Via GitHub

$ git clone [email protected]:ronanguilloux/IsoCodes.git

Autoloading is PSR-0 friendly.

Via Packagist & Composer

Require the latest version of ronanguilloux/isocodes with Composer

$ composer require ronanguilloux/isocodes

Wrappers

With Symfony Validator

Install Soullivaneuh/IsoCodesValidator to get IsoCodes working as Validator for Symfony and Silex.

With CakePHP 3

Install gourmet/validation to get IsoCodes working with CakePHP 3 as a validator.

With Laravel

Install pixelpeter/laravel5-isocodes-validation to get IsoCodes working with Laravel 5 as a validator.

Supported PHP versions

  • 7.3
  • 7.4

Unit testing

$ phpunit --testdox --coverage-text

Make utilities

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

Quality assurance report

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.

License Information

Contributing Code

The issue queue can be found at: https://github.com/ronanguilloux/IsoCodes/issues. See CONTRIBUTING.md.

Special thanks

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.

Comments
  • Make Ssn as a singleton class

    Make Ssn as a singleton class

    This PR is related to #12 and also to #33 proposition.

    Ssn is now a singleton class in order to make validate function static like other validators does.

    I also add tests that simply call generate function to verify if is not crashing. I don't know how to assert results of generate, any advice @ronanguilloux?

    Method based on this article: http://www.phptherightway.com/pages/Design-Patterns.html#singleton

    Please not: This is BC break for libraries that implement IsoCodes. Must be on 1.2 version at least.

    question 
    opened by soullivaneuh 17
  • Use generated zipcode patterns

    Use generated zipcode patterns

    Use auto-generated sources from http://i18napis.appspot.com with more countries available.

    Deprecated the validateNetherlands($zipcode) calls in favor of the validate($zipcode, 'nl') so they could be removed some time (Or you would need to add methods for each country?)

    This doesn't change the tests (and haven't run the tests yet). Test could perhaps be modified to verify the examples from zipex in the data, but that wouldn't be needed if the source already tested those.

    enhancement 
    opened by barryvdh 14
  • travis: PHP 7.0 nightly added + few improvements

    travis: PHP 7.0 nightly added + few improvements

    • --dev is by default for almost a year
    • use Travis' composer and phpunit (no need to maintain them by yourself)
    • also, phpunit.xml.dist is loaded by default (if phpunit.xml not found)
    question 
    opened by TomasVotruba 14
  • Nif validation only for Spain?

    Nif validation only for Spain?

    I see on your README file that your NIF validator if for Spain codes (Número de Identificación Fiscal) but, stop me if I'm wrong, NIF codes are Europeans.

    See here: http://ec.europa.eu/taxation_customs/taxation/tax_cooperation/mutual_assistance/tin/index_fr.htm

    Are we speaking about the same NIF?

    Is your NIF validator compliant with EU conventions?

    Regards

    question 
    opened by soullivaneuh 14
  • SIRET Issue with

    SIRET Issue with "La Poste" according INSEE

    Hello,

    According Wikipedia, the following exception exists and should be taken in consideration: https://fr.wikipedia.org/wiki/Formule_de_Luhn#Cas_particulier

    enhancement 
    opened by Geolim4 10
  • added BSN

    added BSN

    | Q             | A
    | ------------- | ---
    | Bug fix?      | no
    | New feature?  | yes
    | BC breaks?    | no
    | Deprecations? | no
    | Tests pass?   | yes
    | Fixed tickets | -
    
    opened by abbert 8
  • CreditCardTest failing on windows

    CreditCardTest failing on windows

    Test for this card number fails on windows because a number this long can't be stored as an integer. Instead it becomes a float and when converted into string it is 6.3041E+15 instead of 6304100000000008.

    In my opinion CreditCard::validate should only allow string arguments or at least throw an exception if a float is passed as parameter to prevent this error.

    opened by enumag 8
  • Travis improve

    Travis improve

    In a nutshell:

    • composer vendor directory cache
    • dist-mode for composer update
    • GitHub oauth. You need to set a token on GITHUB_OAUTH_TOKEN variable. Mark it as private to secure it.
    • Lowest deps mode to check composer dependencies going right.
    • Some Travis optimizations for composer. Some time composer could be long to resolve and consume huge memory

    I have some another optimizations idea but I'll talk about it later on another PR. ;-)

    opened by soullivaneuh 8
  • Traditional to short array syntax

    Traditional to short array syntax

    Since #24, this project require php >=5.4.

    So we can now use the new array short syntax as defined on this change-log: http://php.net/manual/en/migration54.new-features.php

    @stof just for advice, are you agree with that?

    Regards.

    question 
    opened by soullivaneuh 8
  • Singleton class for SSN

    Singleton class for SSN

    The SSN validator is special. We have to instantiate it before use it for validation.

    I think is for avoid code generation (generate('CA')) on each validation?

    In this case, could we think about use it as a singleton class?

    See here (FR): http://fr.wikipedia.org/wiki/Singleton_%28patron_de_conception%29#PHP_5

    I suggest it because with this code design, I will have to instantiate it on each validation with my Symfony Validator wrapping.

    Could work on it. This should be on a next major release.

    opened by soullivaneuh 6
  • php with bcmath required for some checks but not mentioned in the docs

    php with bcmath required for some checks but not mentioned in the docs

    PHP is required to be compiled with "--enable-bcmath" for some checks but this is not mentioned in the documentation. Please update the documentation or provide a fallback method if possible.

    Thomas

    opened by tsfoer 6
  • Finnish personal identity code (HETU) - New punctuation marks for personal identity codes 1 January 2023

    Finnish personal identity code (HETU) - New punctuation marks for personal identity codes 1 January 2023

    | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | -

    https://dvv.fi/en/reform-of-personal-identity-code New punctuation marks for personal identity codes 1 January 2023

    The new punctuation marks are:

    • For those born in the 2000s: B, C, D, E and F, from letter B in addition to the current letter A
    • For those born in the 20th century, Y, X, W, V, U, from the letter Y in addition to the current symbol -.

    DVV's assessment of the implementation schedule Situation 11/2022: According to the current estimate, personal IDs with new separators under the new separator decree will be issued for the first time in April2024. The estimate is based on the average volume of issuances from 2016 to 2021 and the estimation of future issuances. If the need for personal identity codes increases, for example, due to persons moving to Finland for work, new separators may be introduced sooner.

    Previous pull requests for Finnish ID (HETU): https://github.com/ronanguilloux/IsoCodes/pull/128, https://github.com/ronanguilloux/IsoCodes/pull/130

    opened by stiflerbox 1
  • False positive result

    False positive result

    PhoneNumber::validate("+49 171 1234567", "DE") // valid number, all ok
    
    PhoneNumber::validate("+49 171 1234567tt", "DE") //passes validation, must be false
    
    PhoneNumber::validate("+49 171 1234567ttttt", "DE") //catches as wrong number
    

    package vertion: 2.3.6

    opened by giolaza 0
  • Add a `.gitattributes` file to reduce vendor bundle size

    Add a `.gitattributes` file to reduce vendor bundle size

    Example: https://github.com/code-lts/Laravel-FCM/blob/main/.gitattributes

    vendor/ronanguilloux/isocodes
    ├── CHANGELOG.md
    ├── .circleci                  <------------------ remove the folder
    │   └── config.yml
    ├── CODE_OF_CONDUCT.md <----- remove it
    ├── commit.template <----- remove it
    ├── composer.json
    ├── CONTRIBUTING.md
    ├── .coveralls.yml <----- remove it
    ├── .gitignore <----- remove it
    ├── LICENSE
    ├── Makefile <----- remove it
    ├── .php_cs.php <----- remove it
    ├── phpunit.xml.dist <----- remove it
    ├── pre-commit <----- remove it
    ├── README.md
    ├── .scrutinizer.yml <----- remove it
    ├── src [...]
    ├── tests [...]                   <------------------ remove the folder ?
    └── .travis.yml <----- remove it
    
    6 directories, 108 files
    
    opened by williamdes 1
  • Convert three assignment statements to the usage of combined operators

    Convert three assignment statements to the usage of combined operators

    :eyes: Some source code analysis tools can help to find opportunities for improving software components. :thought_balloon: I propose to increase the usage of combined operators accordingly.

    diff --git a/src/IsoCodes/CreditCard.php b/src/IsoCodes/CreditCard.php
    index b663322..3fd260e 100644
    --- a/src/IsoCodes/CreditCard.php
    +++ b/src/IsoCodes/CreditCard.php
    @@ -35,7 +35,7 @@ class CreditCard implements IsoCodeInterface
                 if ((($length - $i) % 2) == 0) {
                     $digit = (int) $digit * 2;
                     if ($digit > 9) {
    -                    $digit = $digit - 9;
    +                    $digit -= 9;
                     }
                 }
                 $tot += (int) $digit;
    diff --git a/src/IsoCodes/Iban.php b/src/IsoCodes/Iban.php
    index 4bb97c8..52d9a9b 100644
    --- a/src/IsoCodes/Iban.php
    +++ b/src/IsoCodes/Iban.php
    @@ -110,7 +110,7 @@ class Iban implements IsoCodeInterface
                 return false;
             }
             // Fetch needed string for validation
    -        $check = $check.substr($iban, 0, 4);
    +        $check .= substr($iban, 0, 4);
             // Replace characters by decimal values
             $check = str_replace(
                 ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'],
    diff --git a/src/IsoCodes/Iswc.php b/src/IsoCodes/Iswc.php
    index 9ead1a7..82a8394 100644
    --- a/src/IsoCodes/Iswc.php
    +++ b/src/IsoCodes/Iswc.php
    @@ -28,7 +28,7 @@ class Iswc extends Luhn implements IsoCodeInterface
             $sum = 1;
     
             for ($i = 1; $i <= 9; ++$i) {
    -            $sum = $sum + $i * (int) $iswc[$i];
    +            $sum += $i * (int) $iswc[$i];
             }
     
             $rem = $sum % 10;
    
    opened by elfring 0
  • fix(gtin8): wrong interface signature match

    fix(gtin8): wrong interface signature match

    This cause incompatible signature errors on PHP >=7.

    We may also set the strict typing signature for the main interface, but it should be done on a new major release as it's a breaking change for implementation.

    opened by soullivaneuh 3
Releases(2.2.0)
Owner
Ronan Guilloux
Having fun with Open-Source since 1998.
Ronan Guilloux
PHP library to validate and format license plate numbers.

License plate validator and formatter CI Status Lint Coverage Tests This library can be used to validate and format license plate numbers. Countries s

Automex.website 1 Oct 19, 2022
PHP library for ArCaptcha. This package supports PHP 7.3+.

PHP ArCaptcha Library PHP library for ArCaptcha. This package supports PHP 7.3+. List of contents PHP ArCaptcha Library List of contents Installation

Mohammad Abbasi 10 Aug 12, 2022
A simple filtering library for PHP

Filterus - A flexible PHP 5.3 filter package Filter Methods: Each filter class has two primary methods: $filter->filter($var) - returns a modified ver

Anthony Ferrara 451 Dec 27, 2022
PHP library to validate and convert ISBNs and EANs

biblys/isbn biblys/isbn can be used to: validate a string against the ISBN-10, ISBN-13 and EAN-13 formats convert an ISBN to ISBN-10, ISBN-13, EAN-13

Biblys 48 Apr 10, 2022
PHP Email address validator - A library for validating emails against several RFC.

EmailValidator A library for validating emails against several RFC. Supported RFCs This library aims to support RFCs: 5321, 5322, 6530, 6531, 6532, 10

Eduardo Gulias Davis 10.7k Jun 13, 2022
FyreValidation is a free, open-source validation library for PHP.

FyreValidation FyreValidation is a free, validation library for PHP. Table Of Contents Installation Validators Rules Error Messages Installation Using

Elusive 0 Jan 15, 2022
Valitron is a simple, elegant, stand-alone validation library with NO dependencies

Valitron: Easy Validation That Doesn't Suck Valitron is a simple, minimal and elegant stand-alone validation library with NO dependencies. Valitron us

Vance Lucas 1.5k Dec 30, 2022
[READ-ONLY] Validation library from CakePHP. This repo is a split of the main code that can be found in https://github.com/cakephp/cakephp

CakePHP Validation Library The validation library in CakePHP provides features to build validators that can validate arbitrary arrays of data with eas

CakePHP 39 Oct 11, 2022
Library that offers Input Filtering based on Annotations for use with Objects. Check out 2.dev for 2.0 pre-release.

DMS Filter Component This library provides a service that can be used to filter object values based on annotations Install Use composer to add DMS\Fil

Rafael Dohms 89 Nov 28, 2022
Light and extendable schema validation library

Light PHP validation library For everyone who uses MongoDB or other NoSQL solution and cares about what client sends to his/her database and looking f

Alexander Serkin 43 Sep 28, 2022
An extensible validation library for your data with sane defaults.

Hird Hirds, also known as housecarls, was a gathering of hirdmen, who functioned as the king's personal guards during the viking age and the early mid

Asko Nõmm 13 Apr 23, 2022
A re-write of rakit/validation, a standalone validation library inspired by Laravel Validation

Somnambulist Validation This is a re-write of rakit/validation, a standalone validator like Laravel Validation. In keeping with rakit/validation, this

Somnambulist Tech 18 Dec 14, 2022
php binding for IUP toolkit

php-iup php-ffi experiment php7.4 interface to the IUP toolkit for building GUI's. Description IUP-Toolkit IUP is a multi-platform toolkit for buildin

Shubham Chaudhary 20 Nov 13, 2022
A PHP package for validating/generating/formatting an IRS document number (CPF/CNPJ)

A PHP package for validating/generating/formatting an IRS document number (CPF/CNPJ)

null 7 Dec 15, 2022
Modern PHP validator on steroids for validating forms and/or array's.

Modern PHP Validator - Standalone Validation on Steroids Introduction Head first example Installation Adding fields for validation Execute validation

Kris Kuiper 5 Oct 5, 2022
Laravel Countries is a bundle for Laravel, providing Almost ISO 3166_2, 3166_3, currency, Capital and more for all countries.

Laravel Countries Laravel Countries is a bundle for Laravel, providing Almost ISO 3166_2, 3166_3, currency, Capital and more for all countries. Please

Christoph Kempen 695 Dec 30, 2022
Ressource Management and Manufacturing execution system Web for industry (sheet metal, machining, mold ...)

WEB ERP MES Ressource and Manufacturing execution system Web WEM is a business management web application using Laravel 8 and bootstrap 4.6. Why WEM ?

null 28 Dec 30, 2022
WPForms coding standards are based on the WordPress Coding Standards and the PHPCompatibility Coding Standards and help create strict and high-quality code.

WPForms coding standards are based on the WordPress Coding Standards and the PHPCompatibility Coding Standards and help create strict and high-quality code.

Awesome Motive, Inc. 7 Nov 29, 2022
Open Standards Protocol for global Trade & Finance.

Open Standards Protocol for global Trade & Finance. Mitigate Counter-Party Risk by making your Financial Instruments Interoperable & Liquid Start trial under regulatory sandbox environment. Digital Bond, Invoice Factoring, R3 Corda Bridge on XinFin Blockchain

XinFin (eXchange inFinite) 9 Dec 7, 2022
A small library for validating International Bankaccount Numbers (IBANs) based on the IBAN Registry provided by SWIFT

A small library for validating International Bankaccount Numbers (IBANs) based on the IBAN Registry provided by SWIFT

Jan Schädlich 69 Dec 18, 2022