From 85051cb19338840284a02bfad99de0d76d64ce6d Mon Sep 17 00:00:00 2001 From: Reza Date: Sat, 19 Oct 2024 11:57:12 +0200 Subject: [PATCH] validators null fix --- lib/validation/validators.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/validation/validators.go b/lib/validation/validators.go index 34e0e13..b8eb8b4 100644 --- a/lib/validation/validators.go +++ b/lib/validation/validators.go @@ -342,7 +342,7 @@ func intValidator(match []string, value *generic.Value) error { func numericalValidator(match []string, value *generic.Value) error { var s = value.String() - if s == "" { + if s == "" || s == "" { return nil } var v = value.Float64() @@ -379,6 +379,9 @@ func numericalValidator(match []string, value *generic.Value) error { func lenValidator(match []string, value *generic.Value) error { var v = value.String() + if v == "" || v == "" { + return nil + } var size = len(v) t, _ := strconv.ParseInt(match[2], 10, 6) length := int(t) @@ -422,6 +425,9 @@ func nameValidator(match []string, value *generic.Value) error { func alphaValidator(match []string, value *generic.Value) error { var v = value.String() + if v == "" || v == "" { + return nil + } for _, r := range v { if !((r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || r == ' ') { return fmt.Errorf("is not alpha") @@ -432,6 +438,9 @@ func alphaValidator(match []string, value *generic.Value) error { func alphaNumericValidator(match []string, value *generic.Value) error { var v = value.String() + if v == "" || v == "" { + return nil + } for _, r := range v { if !((r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') || r == ' ') { return fmt.Errorf("is not alpha") @@ -444,6 +453,9 @@ var emailRegex = regexp.MustCompile(`(?i)^[a-z0-9_\-.]{2,}(\+\d+)?@[a-z0-9_-]{2, func emailValidator(match []string, value *generic.Value) error { var v = value.String() + if v == "" || v == "" { + return nil + } if strings.TrimSpace(v) == "" { return nil } @@ -455,7 +467,7 @@ func emailValidator(match []string, value *generic.Value) error { func requiredValidator(match []string, value *generic.Value) error { var v = value.String() - if strings.TrimSpace(v) == "" { + if strings.TrimSpace(v) == "" || v == "" { return fmt.Errorf("is required") } return nil