Skip to content

Commit 85051cb

Browse files
committed
validators null fix
1 parent a5185d9 commit 85051cb

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lib/validation/validators.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ func intValidator(match []string, value *generic.Value) error {
342342

343343
func numericalValidator(match []string, value *generic.Value) error {
344344
var s = value.String()
345-
if s == "" {
345+
if s == "" || s == "<nil>" {
346346
return nil
347347
}
348348
var v = value.Float64()
@@ -379,6 +379,9 @@ func numericalValidator(match []string, value *generic.Value) error {
379379

380380
func lenValidator(match []string, value *generic.Value) error {
381381
var v = value.String()
382+
if v == "" || v == "<nil>" {
383+
return nil
384+
}
382385
var size = len(v)
383386
t, _ := strconv.ParseInt(match[2], 10, 6)
384387
length := int(t)
@@ -422,6 +425,9 @@ func nameValidator(match []string, value *generic.Value) error {
422425

423426
func alphaValidator(match []string, value *generic.Value) error {
424427
var v = value.String()
428+
if v == "" || v == "<nil>" {
429+
return nil
430+
}
425431
for _, r := range v {
426432
if !((r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || r == ' ') {
427433
return fmt.Errorf("is not alpha")
@@ -432,6 +438,9 @@ func alphaValidator(match []string, value *generic.Value) error {
432438

433439
func alphaNumericValidator(match []string, value *generic.Value) error {
434440
var v = value.String()
441+
if v == "" || v == "<nil>" {
442+
return nil
443+
}
435444
for _, r := range v {
436445
if !((r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') || r == ' ') {
437446
return fmt.Errorf("is not alpha")
@@ -444,6 +453,9 @@ var emailRegex = regexp.MustCompile(`(?i)^[a-z0-9_\-.]{2,}(\+\d+)?@[a-z0-9_-]{2,
444453

445454
func emailValidator(match []string, value *generic.Value) error {
446455
var v = value.String()
456+
if v == "" || v == "<nil>" {
457+
return nil
458+
}
447459
if strings.TrimSpace(v) == "" {
448460
return nil
449461
}
@@ -455,7 +467,7 @@ func emailValidator(match []string, value *generic.Value) error {
455467

456468
func requiredValidator(match []string, value *generic.Value) error {
457469
var v = value.String()
458-
if strings.TrimSpace(v) == "" {
470+
if strings.TrimSpace(v) == "" || v == "<nil>" {
459471
return fmt.Errorf("is required")
460472
}
461473
return nil

0 commit comments

Comments
 (0)