GithubHelp home page GithubHelp logo

ronanguilloux / isocodes Goto Github PK

View Code? Open in Web Editor NEW
789.0 22.0 76.0 592 KB

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

License: GNU General Public License v3.0

Makefile 2.37% PHP 96.91% Shell 0.71%
gtin php international-finance administrations isocodes gs1

isocodes's Introduction

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.

Build status

License Latest Stable Version Build Status Scrutinizer Code Quality SymfonyInsight 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.

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.

isocodes's People

Contributors

antoinelemaire avatar artemgoutsoul avatar barryvdh avatar beilsma avatar drieschel avatar enumag avatar florin1 avatar g3rd0 avatar geolim4 avatar ickbinhier avatar ilubenets avatar janlanger avatar jarlskov avatar jcomack avatar julienbreux avatar kassnl avatar kitbs avatar kookynerd avatar kukulich avatar loicfavory avatar micheleangioni avatar nutama avatar nykopol avatar pp3345 avatar pvankouteren avatar readmecritic avatar ronanguilloux avatar seldaek avatar soullivaneuh avatar stof avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

isocodes's Issues

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.

Separate PHP tools from project dependencies

PHP tools (phpunit / phpcs / phpmd...) should be separated from project dependencies because:

  • Lot of dependencies to download for only one project.
  • Could easily make conflict

Will make a PR proposition about that.

English code and comment?

Hi and thanks for this project, found a lot of missing validators.

I'm planning to wrap them with a Symfony Validator extension, I'll speak about it later! :-)

Have you plan to normalize code on command to get it on full English?

Could make thinks easier for world wide contributing.

Some french code here, for example: https://github.com/ronanguilloux/IsoCodes/blob/master/src/IsoCodes/OrganismeType12NormeB2.php
And spanish comments here: https://github.com/ronanguilloux/IsoCodes/blob/master/src/IsoCodes/Nif.php

Regards

IsoCodesInterface

It would be great to have a IsoCodesInterface interface which will be implemented by all IsoCodes validator.

This will make a proper code structure and make some more strict rules for another validator contributions.

This can be done now if we solve #12.

OrganismeType12NormeB2 seems to be the only one that accepting two arguments instead of one on validate method.

BTW, I not implemented it on my wrappers because I don't know how it works. More exactly, what the second parameter mean?

Can you give me some clarification about it?

Thanks.

Suggest ext-bcmath

Suggest ext-bcmath on composer.json on throw error on needed validator.

See related #7

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.

More zipcodes

Currently you have a few zipcodes available, perhaps add them all automatically?

Instead of creating a method for each country, perhaps create an array with data for all countries?

This list exists but is deprecated:
http://unicode.org/cldr/trac/browser/trunk/common/supplemental/postalCodeData.xml

Links to:
http://i18napis.appspot.com/address
http://i18napis.appspot.com/address/data/GB
"zip": "GIR[ ]?0AA|((AB|AL|B|BA|BB|BD|BH|BL|BN|BR|BS|BT|BX|CA|CB|CF|CH|CM|CO|CR|CT|CV|CW|DA|DD|DE|DG|DH|DL|DN|DT|DY|E|EC|EH|EN|EX|FK|FY|G|GL|GY|GU|HA|HD|HG|HP|HR|HS|HU|HX|IG|IM|IP|IV|JE|KA|KT|KW|KY|L|LA|LD|LE|LL|LN|LS|LU|M|ME|MK|ML|N|NE|NG|NN|NP|NR|NW|OL|OX|PA|PE|PH|PL|PO|PR|RG|RH|RM|S|SA|SE|SG|SK|SL|SM|SN|SO|SP|SR|SS|ST|SW|SY|TA|TD|TF|TN|TQ|TR|TS|TW|UB|W|WA|WC|WD|WF|WN|WR|WS|WV|YO|ZE)(\\d[\\dA-Z]?[ ]?\\d[ABD-HJLN-UW-Z]{2}))|BFPO[ ]?\\d{1,4}",

I would also suggest that the country code is easier to use, instead of the name?

+1 US phone number

/^(\+\d)*\s*(\(\d{3}\)\s*)*\d{3}(-{0,1}|\s{0,1})\d{2}(-{0,1}|\s{0,1})\d{2}$/

SsnTest failing on windows

SsnTest is failing if the Ssn.php file has CRLF end of lines instead of just LF. I tried to fix it using some line normalization function but it didn't work for unknown reason.

This should be considered a bug, the script should not depend on the EOL style used since that can be changed unpredictably when deploying for example.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.