barcodes/validation/validate.go

30 lines
771 B
Go
Raw Normal View History

2023-09-01 19:08:59 +01:00
package validation
import "fmt"
func Validate(input string, format string) bool {
2023-09-01 20:50:47 +01:00
rule, exists := formatRules[format]
2023-09-01 19:08:59 +01:00
if !exists {
fmt.Printf("Error: No rule found for format '%s'\n", format)
return false
}
if uint64(len(input)) < rule.minLength || uint64(len(input)) > rule.maxLength {
fmt.Printf("Validation Error: Length must be between %d and %d\n", rule.minLength, rule.maxLength)
return false
}
if !rule.charset.MatchString(input) {
fmt.Println("Validation Error: Contains illegal characters")
return false
}
if uint64(len(input))%uint64(rule.divisible) != 0 {
fmt.Printf("Validation Error: Length must be a multiple of %d", rule.divisible)
return false
}
2023-09-01 21:51:30 +01:00
fmt.Printf("Validation passed for barcode type %s\n", format)
2023-09-01 19:08:59 +01:00
return true
}