Git Product home page Git Product logo

Comments (5)

ProCessor00 avatar ProCessor00 commented on September 24, 2024

Hey,
your code does not work with common ISBN 13 and UPC codes. Try followings

ISBN: 9780241235645
UPC: 883929344130

Works with ISBn 10 e.g.
1870089049

Thanks

Experiencing the same issue here.

from barcode-validator.

gwillings avatar gwillings commented on September 24, 2024

Ok I think I have a fix for this.

$checkdigit = (10 - (($odd_digits * 3 + $even_digits) % 10) % 10);

According to https://www.gs1.org/services/how-calculate-check-digit-manually
the multiplier is based on code length.

If you change this method to:

protected static function calculateEANCheckDigit($code)
{
    // Split odd-/even-positioned digits (except the last one).
    preg_match_all('/(\d)(\d){0,1}/', $code, $digits);
    $oddDigits = array_sum($digits[1]);
    $evenDigits = array_sum($digits[2]);
    if (strlen($code) % 2 == 0) {
        $evenDigits *= 3;
    } else {
        $oddDigits *= 3;
    }
    $sum = $oddDigits + $evenDigits;
    // nearest equal or higher multiple of ten
    $multiple = ceil($sum / 10) * 10;
    $checkDigit = $multiple - $sum;
    return $checkDigit;
}			

I have tested this on the codes submitted in this issue thread and it seems to fix the issue.

from barcode-validator.

ProCessor00 avatar ProCessor00 commented on September 24, 2024

from barcode-validator.

imelgrat avatar imelgrat commented on September 24, 2024

Thanks Geoff. I missed that one. I just updated the code with your version. It works with the codes I have for my internal tests.

from barcode-validator.

gwillings avatar gwillings commented on September 24, 2024

No problem. Glad it was useful.

from barcode-validator.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.