Panel field: page. validate input?

the panel field ‘page’ does have nice auto completion but not validation, yet, right?

do i have to write a custom one with regex? https://getkirby.com/docs/developer-guide/objects/validators
which would allow checking if page exists.

myfield:
  type: page
  validate: myuriregex

simple but not foolproff. just use regex to check uri.

myfield:
  type: page
  validate: 
    match: "\\" # insert fancy regex here

or does kirby / toolkit already have an uri validation code somewhere? did not find it yet.

Do you want to validate if the page exists or just if it is a valid URI?
You can check the URI format with the following rule:

myfield:
  type: page
  validate: 
    match: "{^[a-z0-9/]+$}"

The regex will match for any combination of lowercase letters, numbers and slashes.

first would be better. but i can do that i think myself.

but i am not good at regex. why does your suggestion not match if try it on http://regexr.com/3dove

You have to remove the curly braces, they are just an alternative to the slashes that RegExr provides by default.

You can validate if the page exists with your own validator, see the docs you linked to. It can be just something like (untested):

v::$validators['page'] = function($uri) {
  return page($uri) !== false;
};

together with the blueprint:

myfield:
  type: page
  validate: page

your regex does not support adding minus in slug. so this should work?

/\b[a-z0-9/-]+\b/g

http://regexr.com/3dp7s

Yes and no. If you want to match a minus as well, use:

myfield:
  type: page
  validate: 
    match: "{^[a-z0-9/-]+$}"

Your RegEx also matches if there are wrong characters in the page URI as it doesn’t enforce that the character group has to match from the beginning (^) to the end ($).

However, as I wrote, actually checking if the page exists as in my example above is a better and more robust solution anyway.

i see. thanks for explaining about the character group. so on regexr i should only check a single uri not multiple vairants at once. i was able to verify your expression on regexr now.

What you could also do at RegExr is to enable the “multiline” flag (on the top right). You can then put several test cases on multiple lines and check if the ones that should match match and the ones that shouldn’t don’t match.