Small built-in validator set #6

Closed
opened 2026-09-07 12:22:51 +00:00 by claude · 0 comments
Member

Built-in set today: Chars / ExceptChars, MinLength / MaxLength, Email, URL, UUID, Equal, In / NotIn, the numeric Min / Max family, MinSize / MaxSize. validator/v10 ships ~100 tags; the gap is wide enough that people will hit a missing check early.

PR #9 makes a first, conservative addition, all in the existing style (constructor → func(T) error, sentinel error, table tests + Example):

  • Required[T comparable]() — non-zero value
  • Prefix / Suffix / Containsstrings.HasPrefix / HasSuffix / Contains
  • Match(*regexp.Regexp) — arbitrary pattern

Further candidates (not in the PR — worth triaging)

  • Between / Range for the numeric types (currently need All(Min, Max))
  • NotBlankRequired after strings.TrimSpace
  • Lower / Upper — case checks
  • OneOf as a readable alias for In
  • JSON, Base64, Hex
  • IP, CIDR, Hostname, Port
  • time bounds (Before / After) for time.Time

Keep every addition dependency-free and value-level; anything needing reflection or a struct belongs in #4.

Built-in set today: `Chars` / `ExceptChars`, `MinLength` / `MaxLength`, `Email`, `URL`, `UUID`, `Equal`, `In` / `NotIn`, the numeric `Min` / `Max` family, `MinSize` / `MaxSize`. `validator/v10` ships ~100 tags; the gap is wide enough that people will hit a missing check early. **PR #9** makes a first, conservative addition, all in the existing style (constructor → `func(T) error`, sentinel error, table tests + Example): - `Required[T comparable]()` — non-zero value - `Prefix` / `Suffix` / `Contains` — `strings.HasPrefix` / `HasSuffix` / `Contains` - `Match(*regexp.Regexp)` — arbitrary pattern ### Further candidates (not in the PR — worth triaging) - `Between` / `Range` for the numeric types (currently need `All(Min, Max)`) - `NotBlank` — `Required` after `strings.TrimSpace` - `Lower` / `Upper` — case checks - `OneOf` as a readable alias for `In` - `JSON`, `Base64`, `Hex` - `IP`, `CIDR`, `Hostname`, `Port` - time bounds (`Before` / `After`) for `time.Time` Keep every addition dependency-free and value-level; anything needing reflection or a struct belongs in #4.
Sign in to join this conversation.