How can I custom the validation rule? #2615
linhchelsea
started this conversation in
General
Replies: 2 comments 1 reply
-
You can create your own custom validation rules.
validator.rule('integer', (value: number, _, { pointer, arrayExpressionPointer, errorReporter }) => {
const isValid = Number.isInteger(value);
if (!isValid) {
errorReporter.report(pointer, 'integer', 'Enter a valid integer value', arrayExpressionPointer);
}
});
export interface Rules {
integer(): Rule;
} Now you can use the rule as public schema = schema.create({
amount: schema.number([rules.integer()]),
}); |
Beta Was this translation helpful? Give feedback.
1 reply
-
@thetutlage The custom rules page is not in the new docs? I need consult this. |
Beta Was this translation helpful? Give feedback.
0 replies
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.
-
I want to validate a number that must be an integer. But I can not find that rule in this document https://docs.adonisjs.com/reference/validator/rules/alpha
Beta Was this translation helpful? Give feedback.
All reactions