Closed eNzyOfficial closed 6 years ago
If you will go through the docs, under Syntax guide
, it talks about the limitations of the syntax https://indicative.adonisjs.com/docs/syntax-guide#_limitations
What you need is to use the rule
function over a string.
slug: [
rule('required'),
rule('regex', '/^[a-zA-Z0-9]+(?:-[a-zA-Z0-9]+)*$/')
]
When I had a look through the adonis docs I couldn't find anything about using rule(), could you point me in the right direction?
I believe it will be same
const { rule } = use('Validator')
Awesome, thanks!
Hey,
I had a quick look and saw there was an issue opened and closed as fixed. However I seem to be still getting the same problem.
Returns
Invalid flags supplied to RegExp constructor '-[a-zA-Z0-9]+)*$/'
(On a side note, I am aware that there is the
slug
sanitizer, but I would like to check the db for uniqueness before hand, plus, it seems to add dashes between numbers, regardless of where they are, eg.h3ll0-w0rld
would becomeh-3-ll-0-w-0-rld
rather thanh3ll0-w0rld
)