Not Blank validator #669
-
How do you validate blank string? I can achieve this using resolver but is there any other way? I know there is minLength but it does not validate whitespace. With go-validator I can use notblank |
Beta Was this translation helpful? Give feedback.
Answered by
danielgtaylor
Dec 5, 2024
Replies: 1 comment 1 reply
-
@mrguamos you should be able to use the JSON Schema huma.Get(api, "/demo", func(ctx context.Context, input *struct {
NotBlank string `query:"notblank" pattern:"^\\S+$"`
}) (*Response, error) { /* ... */ }) https://go.dev/play/p/u-XXqr4iF_u Hope that helps! |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
mrguamos
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@mrguamos you should be able to use the JSON Schema
pattern
field for this, which works for both params and body fields:https://go.dev/play/p/u-XXqr4iF_u
Hope that helps!