Implement creation
This commit is contained in:
@@ -5,7 +5,9 @@ import "regexp"
|
||||
var (
|
||||
ASCII = regexp.MustCompile(`^[\x00-\x7F]+$`)
|
||||
ANY = regexp.MustCompile(`.`)
|
||||
CODABAR = regexp.MustCompile(`^[0-9-$:/.+]+$`)
|
||||
CODE39 = regexp.MustCompile(`^[0-9A-Z\-\.\ $%*+/]+$`)
|
||||
CODE93 = regexp.MustCompile(`^[A-Za-z0-9\-.\$/\+%\s]+$`)
|
||||
NUMERAL = regexp.MustCompile(`^[0-9]+$`)
|
||||
ISO88591 = regexp.MustCompile(`^[\x00-\xFF]+$`)
|
||||
)
|
||||
|
||||
@@ -11,79 +11,82 @@ type rule struct {
|
||||
divisible uint8
|
||||
}
|
||||
|
||||
var aztec = rule{
|
||||
minLength: 1,
|
||||
maxLength: 3067,
|
||||
charset: *ANY,
|
||||
divisible: 1,
|
||||
}
|
||||
var formatRules = map[string]rule{
|
||||
|
||||
var code39 = rule{
|
||||
minLength: 1,
|
||||
maxLength: 80,
|
||||
charset: *CODE39,
|
||||
divisible: 1,
|
||||
}
|
||||
"2of5": {
|
||||
minLength: 2,
|
||||
maxLength: 80,
|
||||
charset: *NUMERAL,
|
||||
divisible: 2,
|
||||
},
|
||||
|
||||
var code128 = rule{
|
||||
minLength: 1,
|
||||
maxLength: 80,
|
||||
charset: *ASCII,
|
||||
divisible: 1,
|
||||
}
|
||||
"aztec": {
|
||||
minLength: 1,
|
||||
maxLength: 3067,
|
||||
charset: *ANY,
|
||||
divisible: 1,
|
||||
},
|
||||
|
||||
var datamatrix = rule{
|
||||
minLength: 1,
|
||||
maxLength: 2335,
|
||||
charset: *ANY,
|
||||
divisible: 1,
|
||||
}
|
||||
"codabar": {
|
||||
minLength: 1,
|
||||
maxLength: 100,
|
||||
charset: *CODABAR,
|
||||
divisible: 1,
|
||||
},
|
||||
|
||||
var ean8 = rule{
|
||||
minLength: 7,
|
||||
maxLength: 7,
|
||||
charset: *NUMERAL,
|
||||
divisible: 1,
|
||||
}
|
||||
"code39": {
|
||||
minLength: 1,
|
||||
maxLength: 80,
|
||||
charset: *CODE39,
|
||||
divisible: 1,
|
||||
},
|
||||
|
||||
var ean13 = rule{
|
||||
minLength: 12,
|
||||
maxLength: 12,
|
||||
charset: *NUMERAL,
|
||||
divisible: 1,
|
||||
}
|
||||
"code93": {
|
||||
minLength: 1,
|
||||
maxLength: 80,
|
||||
charset: *ASCII,
|
||||
divisible: 1,
|
||||
},
|
||||
|
||||
var ean14 = rule{
|
||||
minLength: 2,
|
||||
maxLength: 80,
|
||||
charset: *NUMERAL,
|
||||
divisible: 2,
|
||||
}
|
||||
"code128": {
|
||||
minLength: 1,
|
||||
maxLength: 80,
|
||||
charset: *ASCII,
|
||||
divisible: 1,
|
||||
},
|
||||
|
||||
var pdf417 = rule{
|
||||
minLength: 1,
|
||||
maxLength: 1100,
|
||||
charset: *ANY,
|
||||
divisible: 1,
|
||||
}
|
||||
"datamatrix": {
|
||||
minLength: 1,
|
||||
maxLength: 2335,
|
||||
charset: *ANY,
|
||||
divisible: 1,
|
||||
},
|
||||
|
||||
var pzn7 = rule{
|
||||
minLength: 7,
|
||||
maxLength: 7,
|
||||
charset: *NUMERAL,
|
||||
divisible: 1,
|
||||
}
|
||||
"ean8": {
|
||||
minLength: 7,
|
||||
maxLength: 7,
|
||||
charset: *NUMERAL,
|
||||
divisible: 1,
|
||||
},
|
||||
|
||||
var qr = rule{
|
||||
minLength: 1,
|
||||
maxLength: 4296,
|
||||
charset: *ISO88591,
|
||||
divisible: 1,
|
||||
}
|
||||
"ean13": {
|
||||
minLength: 12,
|
||||
maxLength: 12,
|
||||
charset: *NUMERAL,
|
||||
divisible: 1,
|
||||
},
|
||||
|
||||
var upca = rule{
|
||||
minLength: 11,
|
||||
maxLength: 11,
|
||||
charset: *NUMERAL,
|
||||
divisible: 1,
|
||||
"pdf417": {
|
||||
minLength: 1,
|
||||
maxLength: 1100,
|
||||
charset: *ANY,
|
||||
divisible: 1,
|
||||
},
|
||||
|
||||
"qr": {
|
||||
minLength: 1,
|
||||
maxLength: 4296,
|
||||
charset: *ISO88591,
|
||||
divisible: 1,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package validation
|
||||
import "fmt"
|
||||
|
||||
func Validate(input string, format string) bool {
|
||||
rule, exists := barcodeRules[format]
|
||||
rule, exists := formatRules[format]
|
||||
if !exists {
|
||||
fmt.Printf("Error: No rule found for format '%s'\n", format)
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user