30 lines
771 B
Go
30 lines
771 B
Go
package validation
|
|
|
|
import "fmt"
|
|
|
|
func Validate(input string, format string) bool {
|
|
rule, exists := formatRules[format]
|
|
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
|
|
}
|
|
|
|
fmt.Printf("Validation passed for barcode type %s\n", format)
|
|
return true
|
|
}
|