tiendanube/gtinvalidation

Validates GTIN product codes.

v1.0 2018-07-25 22:31 UTC

This package is not auto-updated.

Last update: 2024-11-16 10:49:51 UTC


README

Build Status License

GtinValidation is a library for validating the format and check digit of a GTIN.

Requirements

  • PHP 5.4 or higher

Installation

You can find GtinValidation on Packagist. To install GtinValidation in Composer:

{
  "require": {
    "tiendanube/gtinvalidation": "dev-master"
  }
}

Usage

Basic check

To check a GTIN's validity:

<?php

use GtinValidation\GtinValidator;

$gtinValidator = new GtinValidator('0000000000000');
echo $gtinValidator->isValid();

Output

false

Advanced Check

To get more detailed information about the GTIN and its validity, retrieve the GTIN object:

<?php

use GtinValidation\GtinValidator;

$gtinValidator = new GtinValidator('0000000000000');
$gtinObject = $gtinValidator->getGtinObject();

echo $gtinObject->getType() . PHP_EOL;
echo $gtinObject->isValidFormat() . PHP_EOL;
echo $gtinObject->isValid() . PHP_EOL;

Output

GTIN-13
true
false