Can I Sanitize inputs in Validators (V5)? #3314
Unanswered
CodeArtisT75
asked this question in
Help
Replies: 1 comment 1 reply
-
You can just create a custom rule and mutate the value inside it. Here's the guide to creating custom rules. https://docs.adonisjs.com/guides/validator/custom-rules This is how roughly the rule will look like. import { string } from '@ioc:Adonis/Core/Helpers'
import { validator } from '@ioc:Adonis/Core/Validator'
validator.rule('toLowerCase', (value, _, options) => {
if (typeof value !== 'string') {
return
}
options.mutate(value.toLowerCase())
}) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi.
Can I sanitize user inputs in Validators before validating them in the schema?
something like:
or another way to sanitize them inside the validator (outside of the controller).
thanks.
Beta Was this translation helpful? Give feedback.
All reactions