0

As per the documentation I try to import this statement at the beginning of AuthenticationController.js for the validation of incoming request payload

import { schema } from '@ioc:Adonis/Core/Validator'

Then it arise an 'Internal server error with a status code of 500'. However this command works fine

const { validate } = use('Validator')

Is this a version problem? According to my package.json this is the version it says:

"adonis-version": "4.1.0",

If so then how do I go for a regex validation, this is what I tried which didn't work for password validation. It always prints failed:

const rules = {
            password: 'required|min:6|regex:/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d@$!%*#?&^_-]{8,}$/',
        }
        const validation = await validate(request.all(), rules)
        if (validation.fails()) {
            console.log('failed')
        }
Sazzad
  • 176
  • 1
  • 9

1 Answers1

0

This modification worked!

const { validate, rule } = use('Validator')

    const rules = {
        password: [
            rule("required"),
            rule(
                "regex",
                /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d@$!%*#?&^_-]{8,}$/
            ),
        ]
    }
    const validation = await validate(request.all(), rules)
    if (validation.fails()) {
        console.log('failed')
    } else {
        console.log('success')
    }
Sazzad
  • 176
  • 1
  • 9