Alter the value in custom validation function? #957
-
Is there a way to alter the value in a custom validation function? I need to write validators that do not just accept or reject a value, but alter it, sanitizing the value or modifying it in other ways (for example, I need to "normalize" the Unicode form of certain strings). I tried things like: d.validate.RegisterValidationCtx("myvalidator", func(ctx context.Context, fl validator.FieldLevel) bool {
fl.Field().SetString("newvalue")
return true
}, false) But this is causing a panic as, it seems, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
No this is jot possible using validator for multiple reasons, please see/search for the multiple closed issues asking the same :) For sanitization, prior to validation, this library exists https://github.com/go-playground/mold |
Beta Was this translation helpful? Give feedback.
No this is jot possible using validator for multiple reasons, please see/search for the multiple closed issues asking the same :)
For sanitization, prior to validation, this library exists https://github.com/go-playground/mold