PHPackages                             stormpat/container-validator - 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. stormpat/container-validator

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

stormpat/container-validator
============================

Cargo container code validator

2070.7k↓47.4%9PHP

Since Sep 26Pushed 8y ago3 watchersCompare

[ Source](https://github.com/stormpat/Container-validator)[ Packagist](https://packagist.org/packages/stormpat/container-validator)[ RSS](/packages/stormpat-container-validator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Cargo container validator
=========================

[](#cargo-container-validator)

With the Cargo container validator you can check that a container has a valid [ISO 6346](http://en.wikipedia.org/wiki/ISO_6346) code, you can also calculate container check digits, get the cargo container owners code, group code and create new cargo container check digits.

This is a fork from a piece of code (MIT licensed) I found on the web. I have modified some parts, and made the whole thing work with [Composer](http://getcomposer.org/)

Install
-------

[](#install)

Install with composer, or clone the repo to into your project.

With composer, just add to your composer.json

```
"require": {
    "stormpat/container-validator": "dev-master"
}
```

Add the composer autoloading to your bootstrap.

```
require_once __DIR__ . '/vendor/autoload.php';
```

Documentation
-------------

[](#documentation)

Validate container ISO codes (TEXU3070079 = valid, TEXU3070070 != valid)

```
$validator = new Validator\Validator;
$validator->isValid('TEXU3070079'); // true
$validator->isValid('TEXU3070070'); // false
```

To get the diffrent segments from the code you can do,

```
$container = $validator->validate('TEXU3070079');
print_r($container); // Array ( [0] => TEXU3070079 [1] => TEX [2] => U [3] => 307007 [4] => 9 )
```

where:

```
  0 => string 'TEXU3070079' // The code being validated
  1 => string 'TEX' // The containers ownercode
  2 => string 'U' // The containers group code
  3 => string '307007' // The containers registration digit
  4 => string '9' // The containers check digit
```

How to get error messages when the container code is invalid

```
$validator->validate('TEXU3070070');
$validator->getErrorMessages(); // The check digit does not match

$validator->validate(12345678910);
$validator->getErrorMessages(); // The container number must be a string

$validator->validate('C3P0');
$validator->getErrorMessages(); // The container number is invalid
```

Access information about the container:

```
$validator->validate('TEXU3070070');
echo $validator->getOwnerCode(); // TEX
echo $validator->getProductGroupCode(); // U
echo $validator->getRegistrationDigit(); // 307007
echo $validator->getCheckDigit(); // 9
```

Create a check digit to a container that does not have one

```
$validator = new Validator\Validator;
$validator->createCheckDigit('TEXU307007'); // 9
```

Generate container numbers:

```
// $validator->generate( owner-code, product-group-code, number-start, number-end );
$validator = new Validator\Validator;
$validator->generate('TEX','U',1, 100 ));
```

Notes
-----

[](#notes)

- Theres a JavaScript port by Sameer Shemna that can be found [here](https://github.com/sameersemna/Container-validator-JS)

License
-------

[](#license)

The MIT License (MIT)

Copyright (c) 2014 Patrik Storm

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Credits
-------

[](#credits)

Salute to the original author, [gedex.adc](http://www.google.com/gedex.web.id)

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity41

Moderate usage in the ecosystem

Community12

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/9adc38b2b151ae1b0234e3fbf1b1e6e48c682bd6472c59e3044fa6dbe43f862f?d=identicon)[stormpat](/maintainers/stormpat)

---

Top Contributors

[![stormpat](https://avatars.githubusercontent.com/u/1650705?v=4)](https://github.com/stormpat "stormpat (32 commits)")

### Embed Badge

![Health badge](/badges/stormpat-container-validator/health.svg)

```
[![Health](https://phpackages.com/badges/stormpat-container-validator/health.svg)](https://phpackages.com/packages/stormpat-container-validator)
```

###  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)
