---
application: "Intervention Validation"
version: "Version 4"
status: "stable"
---

# GTIN Rule

## Validate a Global Trade Item Number

Learn how to validate Global Trade Item Numbers (GTIN) with the additional validation rules of Intervention Validation for your Laravel application.

> public Intervention\Validation\Rules\Gtin::__construct(array $lengths = [8, 12, 13, 14])

Checks for a valid [Global Trade Item Number](https://en.wikipedia.org/wiki/Global_Trade_Item_Number).

### Parameters

#### lengths (optional)

Optional array of allowed lengths to check only for certain types (GTIN-8, GTIN-12, GTIN-13 or GTIN-14).

### Example

```php
use Illuminate\Support\Facades\Validator;
use Intervention\Validation\Rules\Gtin;

// validate GTIN
$validator = Validator::make($request->all(), [
    'attribute-key' => new Gtin(),
]);
```

```php
use Illuminate\Support\Facades\Validator;
use Intervention\Validation\Rules\Gtin;

// validate GTIN-8 or GTIN-12
$validator = Validator::make($request->all(), [
    'attribute-key' => new Gtin([8, 12]),
]);
```

---

## Become a Sponsor

### Intervention Validation needs your help to keep the project going

Intervention Validation is non-commercial, open source licensed and completely free to use. The considerable
effort required to maintain and develop the software is only possible with the financial support
of sponsors. There are two ways in which you can support this project.

- Support via [GitHub Sponsors](https://github.com/sponsors/Intervention)
- Support via [Ko-Fi](https://ko-fi.com/interventionphp)