dmt-software / gtin-validator
Symfony validator to validate GTIN
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
pkg:composer/dmt-software/gtin-validator
Requires
- php: >=8.3
- symfony/validator: ^7.2
Requires (Dev)
- phpunit/phpunit: ^12.1
README
Validator to validate GTIN numbers.
An UPC number is equal to a GTIN-12 number, EAN or GLN are GTIN-13 numbers and can be validated using the corresponding size.
Installation
composer require dmt-software/gtin-validator
Usage
use DMT\GTIN\Validator\GTIN; use Symfony\Component\Validator\Validator\ValidatorInterface; class Product { #[GTIN(size: 13, message: 'Invalid EAN code.')] public string $ean; } $product = new Product(); $product->ean = '49923315534218'; /** @var ValidatorInterface $validator */ $errors = $validator->validate($product); if (count($errors) > 0) { foreach ($errors as $error) { echo $error->getMessage() . ' ' . $error->getCause(); } } // prints: Invalid EAN code. Number length is not correct.