String
This content is for v0.7. Switch to the latest version for up-to-date documentation.
Use v.String(value, name?, title?) and v.StringP(&value, ...).
Common rules:
v.Is(v.String("Dennis").EqualTo("Dennis"))v.Is(v.String("").Empty())v.Is(v.String(" ").Blank())v.Is(v.String("processing").InSlice([]string{"idle", "processing"}))Length: bytes vs characters
Section titled “Length: bytes vs characters”Byte-based:
v.Is(v.String("123456").MaxBytes(6))v.Is(v.String("123").MinBytes(3))v.Is(v.String("1234").OfByteLength(4))Rune-based (characters):
v.Is(v.String("虎視眈々").MaxLength(4))v.Is(v.String("虎視眈々").OfLengthBetween(2, 4))regex, _ := regexp.Compile("pre-.+")v.Is(v.String("pre-approved").MatchingTo(regex))Pointer-specific rules
Section titled “Pointer-specific rules”var s *stringv.Is(v.StringP(s).Nil())