Hi,
I’d like to use text input validation with regular expression on some of my fields (most of the time simple text fields), but I have some questions about it:
-
The docs say that the pattern
option is for this, but I don’t get it work. I tested pattern: "/[a-z0-9]+/"
and pattern: "{[a-z0-9]+}"
-
My regex are working properly when I set this instead, but I can’t find anything in the docs about a validate
option
validate:
match: "/[a-z0-9]+/"
- Is it intended that I can‘t publish my page when I have a regex validation on a field but leave it empty (no
required: true
of course)? That’s happening at the moment …
Thank you for any hints!
Looks as if it has to look like this:
text:
label: Text
type: text
validate:
match: /([a-z0-9])+$/i
i.e. without the quotes…
Ok, it now works with and without quotes for me.
But when I leave my field empty and change the page status from draft to listed I get an error about a wrong pattern.
Interesting, do you use that field for sorting?
Hi again @texnixe,
no, I don’t use that field for sorting, it’s a simple text field which by the way isn’t required by default within my setup.
I checked my blueprints again and did reset some things to the default but every page that has a field with a regex pattern can’t be published when I leave one of those fields empty.
I think you have to use a regex pattern that allows an empty string as well. Currently, an empty field just doesn’t validate.
Kirby does validate fields when a draft is published. And even though your field is not required, if the content of the field doesn’t validate, you have no chance.
Great, this works! I can’t remember why I did not test this before. Maybe I expected that the field only get validated wehn there is some content.
Thank you!