Comments (5)
Hey,
your code does not work with common ISBN 13 and UPC codes. Try followingsISBN: 9780241235645
UPC: 883929344130Works with ISBn 10 e.g.
1870089049Thanks
Experiencing the same issue here.
from barcode-validator.
Ok I think I have a fix for this.
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.
from barcode-validator.
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.
No problem. Glad it was useful.
from barcode-validator.
Related Issues (6)
- Publish new version to packagist HOT 1
- Update version number HOT 1
- small fix HOT 1
- Autoload not working HOT 1
- length should not invalidate bar code. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from barcode-validator.