Skip to content

Check(...) function

The Check(...) function, similar to the Is(...) function, however with Check(...) the Rules of the Validator parameter are not short-circuited, which means that regardless of whether a previous rule was valid, all rules are checked.

This example shows two rules that fail due to the empty value in the full_name Validator, and since the Validator is not short-circuited, both error messages are added to the error result.

val := v.Check(v.String("", "full_name").Not().Blank().OfLengthBetween(4, 20))
if !val.Valid() {
out, _ := json.MarshalIndent(val.Error(), "", " ")
fmt.Println(string(out))
}

output:

{
"full_name": [
"Full name can't be blank",
"Full name must have a length between \"4\" and \"20\""
]
}