Any validator
With the Any validator, you can set validation rules for any value or pointer.
Below is a valid example of every Any validator rule.
v.Is(v.Any("react").EqualTo("react"))v.Is(v.Any("svelte").Passing(func(val *bool) bool { return val == "svelte" }))var x *bool; v.Is(v.Any(x).Nil())For the EqualTo(v any) rule function, the parameter type must match the type used by the Any() function, otherwise it will be invalid. In the following example, since the value passed to the Any(...) function is int, and EqualTo(...) compares it with int64, the validation is invalid.
valid := v.Is(v.Any(10).EqualTo(int64(10))).Valid()fmt.Println(valid)output
falseIf a pointer is used, the same pointer must be passed to EqualTo(v any) as it is passed to Any(v any), in order to get a valid validation. The following example illustrates it.
// Valid since the same pointers are comparednumberA := 10v.Is(v.Any(&numberA).EqualTo(&numberA)).Valid()
// Invalid since different pointers are comparednumberB := 10v.Is(v.Any(&numberA).EqualTo(&numberB)).Valid()