Skip to content

Validation.IsValid(...) function

This functions allows to check if an specific value in a Validation session is valid or not. This is very useful for conditional logic.

The following example prints an error message if the age value is invalid.

val := v.Is(v.Number(16, "age").GreaterThan(18)).
Is(v.String("single", "status").InSlice([]string{"married", "single"}))
if !val.IsValid("age") {
fmt.Println("Warning: someone underage is trying to sign up")
}

output:

Warning: someone underage is trying to sign up