Init
This commit is contained in:
28
validation/validate.go
Normal file
28
validation/validate.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package validation
|
||||
|
||||
import "fmt"
|
||||
|
||||
func Validate(input string, format string) bool {
|
||||
rule, exists := barcodeRules[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
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user