diff --git a/apps/cards/EAN13.js b/apps/cards/EAN13.js index 01be1c8df..f04417b6a 100644 --- a/apps/cards/EAN13.js +++ b/apps/cards/EAN13.js @@ -24,7 +24,7 @@ class EAN13 extends EAN { constructor(data, options) { // Add checksum if it does not exist - if (data.search(/^[0-9]{12}$/) !== -1) { + if (/^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/.test(data)) { data += checksum(data); } @@ -36,7 +36,7 @@ class EAN13 extends EAN { valid() { return ( - this.data.search(/^[0-9]{13}$/) !== -1 && + /^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/.test(this.data) && +this.data[12] === checksum(this.data) ); } diff --git a/apps/cards/EAN2.js b/apps/cards/EAN2.js index c7ceb059b..840a98ce0 100644 --- a/apps/cards/EAN2.js +++ b/apps/cards/EAN2.js @@ -12,7 +12,7 @@ class EAN2 extends Barcode { } valid() { - return this.data.search(/^[0-9]{2}$/) !== -1; + return /^[0-9][0-9]$/.test(this.data); } encode(){ diff --git a/apps/cards/EAN5.js b/apps/cards/EAN5.js index 77217cd95..241f422e1 100644 --- a/apps/cards/EAN5.js +++ b/apps/cards/EAN5.js @@ -24,7 +24,7 @@ class EAN5 extends Barcode { } valid() { - return this.data.search(/^[0-9]{5}$/) !== -1; + return /^[0-9][0-9][0-9][0-9][0-9]$/.test(this.data); } encode() { diff --git a/apps/cards/EAN8.js b/apps/cards/EAN8.js index 7ffb41c4c..abcf141fc 100644 --- a/apps/cards/EAN8.js +++ b/apps/cards/EAN8.js @@ -20,7 +20,7 @@ class EAN8 extends EAN { constructor(data, options) { // Add checksum if it does not exist - if (data.search(/^[0-9]{7}$/) !== -1) { + if (/^[0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/.test(data)) { data += checksum(data); } @@ -29,7 +29,7 @@ class EAN8 extends EAN { valid() { return ( - this.data.search(/^[0-9]{8}$/) !== -1 && + /^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/.test(this.data) && +this.data[7] === checksum(this.data) ); } diff --git a/apps/cards/UPC.js b/apps/cards/UPC.js index b7488b12c..dd18f25d9 100644 --- a/apps/cards/UPC.js +++ b/apps/cards/UPC.js @@ -7,7 +7,7 @@ const Barcode = require("cards.Barcode.js"); class UPC extends Barcode{ constructor(data, options){ // Add checksum if it does not exist - if(data.search(/^[0-9]{11}$/) !== -1){ + if(/^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/.test(data)){ data += checksum(data); } @@ -15,7 +15,7 @@ class UPC extends Barcode{ } valid(){ - return this.data.search(/^[0-9]{12}$/) !== -1 && + return /^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/.test(this.data) && this.data[11] == checksum(this.data); } diff --git a/apps/cards/UPCE.js b/apps/cards/UPCE.js index bd082dd4d..898abfad0 100644 --- a/apps/cards/UPCE.js +++ b/apps/cards/UPCE.js @@ -41,14 +41,14 @@ class UPCE extends Barcode{ // is a UPC-A check or number system digit. super(data, options); this.isValid = false; - if(data.search(/^[0-9]{6}$/) !== -1){ + if(/^[0-9][0-9][0-9][0-9][0-9][0-9]$/.test(data)){ this.middleDigits = data; this.upcA = expandToUPCA(data, "0"); this.text = options.text || `${this.upcA[0]}${data}${this.upcA[this.upcA.length - 1]}`; this.isValid = true; } - else if(data.search(/^[01][0-9]{7}$/) !== -1){ + else if(/^[01][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/.test(data)){ this.middleDigits = data.substring(1, data.length - 1); this.upcA = expandToUPCA(this.middleDigits, data[0]);