Skip to content

Commit

Permalink
validators null fix
Browse files Browse the repository at this point in the history
  • Loading branch information
iesreza committed Oct 19, 2024
1 parent a5185d9 commit 85051cb
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/validation/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "<nil>" {
return nil
}
var v = value.Float64()
Expand Down Expand Up @@ -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 == "<nil>" {
return nil
}
var size = len(v)
t, _ := strconv.ParseInt(match[2], 10, 6)
length := int(t)
Expand Down Expand Up @@ -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 == "<nil>" {
return nil
}
for _, r := range v {
if !((r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || r == ' ') {
return fmt.Errorf("is not alpha")
Expand All @@ -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 == "<nil>" {
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")
Expand All @@ -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 == "<nil>" {
return nil
}
if strings.TrimSpace(v) == "" {
return nil
}
Expand All @@ -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 == "<nil>" {
return fmt.Errorf("is required")
}
return nil
Expand Down

0 comments on commit 85051cb

Please sign in to comment.