regex

Validates the value against the defined regex. The rule can only be used with the string schema type.

import { schema, rules } from '@ioc:Adonis/Core/Validator'
{
username: schema.string([
rules.regex(/^[a-zA-Z0-9]+$/)
])
}

You can pass the RegExp instance directly.

{
username: schema.string([
rules.regex(new RegExp('^[a-zA-Z0-9]+$'))
])
}