-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add NotBlank validation function. #421
Conversation
Hey @andreiavrammsd sorry for the delay I responded a few days ago but I don't see it here, was having internet issues that day...anyways I'm curious how this is different from combining |
Hello, The value "" (empty string) is caught by required,gt=0, but " " (string made only of spaces) is not. In many situations, I need to make sure there is actually a value inside a string, not only spaces. Thanks! |
Ah I see, I missed the TrimSpace in your validation; I'm not against this but also wanted to suggest an alternate approach; I too have seen that things like this are pretty common and so created another package to help sanitize the data prior to validation. mold which will allow you to trim and sanitize data in a number of ways, even trimming values of maps. My only concern about adding this to the validation lib is that I can see a great number of additional cases eg. streaming map string values or map of map string values... and don;t think it would make sense to have all of them in the std validation package. What do you think about using the modifiers package of the mold lib prior to validation? |
Regarding trimming, is it worth using a library for a simple built-in function? |
If it feels too heavy for the standard library, no problem, we can close it. |
Sorry for the delay, super busy, my only concern is that the validation actually does more that one thing that corresponds https://github.com/go-playground/validator/pull/421/files#diff-e8dcd0f6e62fb5a9257bc99c0891f3f8R1197 eg. both but I definitely see the value in this and other non-standard validations as well so I have a proposal, if we could create some sub-folders for this package Then we can add these sorts of validators here and people can easily register them if they desire, but won't be registered by default. What do you think? |
This could be something. How would you see the non-standard validators registration: (1) including tags or (2) leaving the user the choose a custom tag?
|
@andreiavrammsd I like option #2 but I'd still want them in another package as described because there are still aliases and translations that can go along with the validation and I'm worried about cluttering up the |
45569dd
to
0240486
Compare
Is it starting to look as you thought? |
@andreiavrammsd apologies for the delay, trying to catch up after the holidays, I have not forgotten |
For validating if the current field has a value or length greater than zero.
0240486
to
1d286c8
Compare
@andreiavrammsd looking great! if you could add a note about non-standard then I can merge :) |
Awesome thanks! |
Add NotBlank validation function.
Change Details:
@go-playground/admins