Skip to content

Commit

Permalink
validator fix
Browse files Browse the repository at this point in the history
  • Loading branch information
iesreza committed Oct 22, 2024
1 parent 3361df7 commit 40b6c3e
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/validation/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func digitValidator(match []string, value *generic.Value) error {

var r = regexp.MustCompile("^[0-9]+$")
if !r.MatchString(v) {
return fmt.Errorf("invalid digit value: %s", v)
return fmt.Errorf("invalid digit value")
}

return nil
Expand All @@ -209,16 +209,16 @@ func ipValidator(match []string, value *generic.Value) error {
parts := strings.Split(v, ".")

if len(parts) != 4 {
return fmt.Errorf("invalid IP address: %s", v)
return fmt.Errorf("invalid IP address")
}

for _, x := range parts {
if i, err := strconv.Atoi(x); err == nil {
if i < 0 || i > 255 {
return fmt.Errorf("invalid IP address: %s", v)
return fmt.Errorf("invalid IP address")
}
} else {
return fmt.Errorf("invalid IP address: %s", v)
return fmt.Errorf("invalid IP address")
}

}
Expand All @@ -244,7 +244,7 @@ func domainValidator(match []string, value *generic.Value) error {
}
var regex = regexp.MustCompile(`(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]`)
if !regex.MatchString(v) {
return fmt.Errorf("invalid domain: %s", v)
return fmt.Errorf("invalid domain")
}
return nil
}
Expand Down Expand Up @@ -463,7 +463,7 @@ func emailValidator(match []string, value *generic.Value) error {
if emailRegex.MatchString(v) {
return nil
}
return fmt.Errorf("invalid email %s", v)
return fmt.Errorf("invalid email")
}

func requiredValidator(match []string, value *generic.Value) error {
Expand All @@ -480,7 +480,7 @@ func regexValidator(match []string, value *generic.Value) error {
return nil
}
if !regexp.MustCompile(match[1]).MatchString(v) {
return fmt.Errorf("is not valid %s", v)
return fmt.Errorf("format is not valid")
}
return nil
}
Expand Down

0 comments on commit 40b6c3e

Please sign in to comment.