PHPackages                             juststeveking/gtin-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. juststeveking/gtin-php

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

juststeveking/gtin-php
======================

A PHP package for validating GTIN codes

v1.0.1(5y ago)5127.2k↑10.4%1MITPHPPHP ^7.4|^8.0

Since Jan 13Pushed 5y agoCompare

[ Source](https://github.com/JustSteveKing/gtin-php)[ Packagist](https://packagist.org/packages/juststeveking/gtin-php)[ GitHub Sponsors](https://github.com/JustSteveKing)[ RSS](/packages/juststeveking-gtin-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (5)Versions (3)Used By (0)

A PHP Validator for the GTIN standard
=====================================

[](#a-php-validator-for-the-gtin-standard)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![PHP Version](https://camo.githubusercontent.com/49de24ab087ab125228c46b940bdb2adef5a91dd4dff801d36ac1eafa47cd293/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6a75737473746576656b696e672f7068702d73646b2e7376673f7374796c653d666c61742d737175617265)](https://php.net)[![Latest Version on Packagist](https://camo.githubusercontent.com/9bf1fadbccac82b946cdedadb19b5b7f0f5c9c48bfc6b383beb123e56045dabe/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a75737473746576656b696e672f6774696e2d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/juststeveking/gtin-php)[![Tests](https://github.com/JustSteveKing/gtin-php/workflows/Tests/badge.svg)](https://github.com/JustSteveKing/gtin-php/workflows/Tests/badge.svg)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/0ced63b9fc7f2017b3891ea913937a822c467bae41e1987002d0af3d25dd5f26/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4a75737453746576654b696e672f6774696e2d7068702f6261646765732f7175616c6974792d73636f72652e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/JustSteveKing/gtin-php/?branch=main)[![Total Downloads](https://camo.githubusercontent.com/ada3b3cc73216ec509b5757dbe625aa12eda2ef53284873768704c22e931d25e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a75737473746576656b696e672f6774696e2d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/juststeveking/gtin-php)

A PHP package for validating GTIN codes for use in plain PHP and in Laravel.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require juststeveking/gtin-php
```

Usage PHP
---------

[](#usage-php)

If you are using a framework other than Laravel, or Laravel itself - you can use the `Gtin` class directly to validate aspects or the entire value passed in. You can check out the [specifications for gtin and GS1 here](https://www.gs1.org/docs/barcodes/GS1_General_Specifications.pdf).

Validating correct length
-------------------------

[](#validating-correct-length)

A GTIN is between 8 and 14 characters long.

```
use JustSteveKing\GtinPHP\Gtin;

$correct = 614141999996;
$valid = Gtin::length($correct); // returns true

$incorrect = 123456;
$failed = Gtin::length($incorrect); // returns false
```

Validating that it is an integer
--------------------------------

[](#validating-that-it-is-an-integer)

A GTIN must be an integer value, in php you can easily use `is_int()` however I have provided a method here to also do the same thing:

```
use JustSteveKing\GtinPHP\Gtin;

$correct = 614141999996;
$valid = Gtin::integer($correct); // returns true

$incorrect = '614141999996';
$failed = Gtin::integer($incorrect); // returns false
```

Inspecting the gtin and validating the check digit
--------------------------------------------------

[](#inspecting-the-gtin-and-validating-the-check-digit)

The GTIN is formatted in a very specific way, this is documented fully in the specificas [document](https://www.gs1.org/docs/barcodes/GS1_General_Specifications.pdf)

```
use JustSteveKing\GtinPHP\Gtin;

$correct = 614141999996;
$valid = Gtin::inspect($correct); // returns true

$incorrect = 123456789;
$failed = Gtin::inspect($incorrect); // returns false
```

Validating all aspects in one go
--------------------------------

[](#validating-all-aspects-in-one-go)

```
use JustSteveKing\GtinPHP\Gtin;

$correct = 614141999996;
$valid = Gtin::validate($correct); // returns true

$incorrect = 123456789;
$failed = Gtin::validate($incorrect); // returns false
```

Validating in Laravel
---------------------

[](#validating-in-laravel)

There is a Laravel Rule as well as a validation macro that gets registered with this package, please use in one of the following ways:

```
// using the class directly
public function rules()
{
    return [
        'gtin' => [
            'required',
            new JustSteveKing\GtinPHP\Rules\Gtin,
        ]
    ];
}
```

```
// using the registered macro
public function rules()
{
    return [
        'gtin' => [
            'required',
            Rule::gtin(),
        ]
    ];
}
```

Feel free to use the `Gtin` class directly if that is more convinient.

Testing
-------

[](#testing)

```
composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Steve McDougall](https://github.com/JustSteveKing)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity39

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

1951d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a87fe82b349821ebd49cf57d65c4cd3e33ae0833222a8438d90fe8921ca899ea?d=identicon)[JustSteveKing](/maintainers/JustSteveKing)

---

Top Contributors

[![JustSteveKing](https://avatars.githubusercontent.com/u/6368379?v=4)](https://github.com/JustSteveKing "JustSteveKing (5 commits)")

---

Tags

gtingtin-validatorlaravelpackagephp

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/juststeveking-gtin-php/health.svg)

```
[![Health](https://phpackages.com/badges/juststeveking-gtin-php/health.svg)](https://phpackages.com/packages/juststeveking-gtin-php)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
