0
I am trying to validate a CPF with regex using the Adonis Database.
I tried that way:
const { validations } = use('indicative/validator')
const { validate } = use('Validator')
const rules = (values) => ({
doc: 'string|required|max:11|min:11|regex:'+validations.regex([new RegExp(/([0-9]{2}[\.]?[0-9]{3}[\.]?[0-9]{3}[\/]?[0-9]{4}[-]?[0-9]{2})|([0-9]{3}[\.]?[0-9]{3}[\.]?[0-9]{3}[-]?[0-9]{2})/g)]),
})
const messages = {
regex: field => `${field} don't have the correct format`
}
class StudentController {
async store ({ request, response }) {
const estudante = { ...request.all(), user_id: request.user_id }
const validation = await validate(estudante, rules(rules), messages)
if (validation.fails()) {
return response.validateError(validation)
}
}
But when I make a request for the route that has this function with the value of doc: 39257443828
I get this error report:
doc don’t have the correct format
I tested this regex on some regex sites and this value passes, but in the Validator of the Indicative is indicating that it is not in the format expected by regex.