Skip to content

dmt-software/gtin-validator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GTIN Validator

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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages