# Panel field: page. validate input?

**URL:** <https://forum.getkirby.com/t/panel-field-page-validate-input/4633>\
**Category:** Questions\
**Tags:** v2\
**Created:** [July 7, 2016, 10:50am UTC](https://forum.getkirby.com/t/panel-field-page-validate-input/4633 "2016-07-07T10:50:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [July 7, 2016, 10:50am UTC](https://forum.getkirby.com/t/panel-field-page-validate-input/4633/1 "2016-07-07T10:50:51Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [July 7, 2016, 11:16am UTC](https://forum.getkirby.com/t/panel-field-page-validate-input/4633/2 "2016-07-07T11:16:40Z")

</div>

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:

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

```

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

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [July 7, 2016, 11:32am UTC](https://forum.getkirby.com/t/panel-field-page-validate-input/4633/3 "2016-07-07T11:32:12Z")

</div>

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](http://regexr.com/3dove)

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [July 7, 2016, 11:38am UTC](https://forum.getkirby.com/t/panel-field-page-validate-input/4633/4 "2016-07-07T11:38:28Z")

</div>

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):

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

```

together with the blueprint:

```auto
myfield:
  type: page
  validate: page

```

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [July 8, 2016, 11:05am UTC](https://forum.getkirby.com/t/panel-field-page-validate-input/4633/5 "2016-07-08T11:05:46Z")

</div>

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

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

```

[http://regexr.com/3dp7s](http://regexr.com/3dp7s)

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [July 8, 2016, 11:18am UTC](https://forum.getkirby.com/t/panel-field-page-validate-input/4633/6 "2016-07-08T11:18:36Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [July 8, 2016, 4:03pm UTC](https://forum.getkirby.com/t/panel-field-page-validate-input/4633/7 "2016-07-08T16:03:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [July 8, 2016, 5:43pm UTC](https://forum.getkirby.com/t/panel-field-page-validate-input/4633/8 "2016-07-08T17:43:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 4:57pm UTC](https://forum.getkirby.com/t/panel-field-page-validate-input/4633/9 "2025-02-06T16:57:33Z")

</div>


