asaskevich / govalidator

[Go] Package of validators and sanitizers for strings, numerics, slices and structs
MIT License
6.03k stars 555 forks source link

How to do struct validation for slice of strings #475

Open dancb10 opened 2 years ago

dancb10 commented 2 years ago

Hello, I have tried validating struct element which is slice of strings. I've tried using the following functions but somehow they don't work as expected: "range(min|max)": Range, "length(min|max)": ByteLength, "runelength(min|max)": RuneLength, "stringlength(min|max)": StringLength,

How can you say my slice cannot have more than 5 elements and each element cannot be more than 20 alpha characters? Can you do this with the validator and using struct tags?