# Question about validate: max:

**URL:** <https://forum.getkirby.com/t/question-about-validate-max/4840>\
**Category:** Questions\
**Tags:** v2\
**Created:** [July 31, 2016, 7:44pm UTC](https://forum.getkirby.com/t/question-about-validate-max/4840 "2016-07-31T19:44:49Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![sandbox](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/sandbox/32/2615_2.png) [@sandbox](https://forum.getkirby.com/u/sandbox)\
**Post date:** [July 31, 2016, 7:44pm UTC](https://forum.getkirby.com/t/question-about-validate-max/4840/1 "2016-07-31T19:44:49Z")

</div>

Hi!

I’m doing my first steps with the blueprints and I tryed out that:

```
  title:
    label: Title
    type: text
    validate:
      max: 21

```

If I enter on the kirbiy panel page in the field _Title_ (or my custom text field) a text with 21 characters or less everything works fine. When I enter only digits like `12345` I get the message that I cant save this page.

I know a title consisting only out of digits is very unlikely but who knows.

I hope this helps you to improve kirby! 🕶

---

<div class="post-metadata">

**Author:** ![Thiousi](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thiousi/32/13656_2.png) [@Thiousi](https://forum.getkirby.com/u/Thiousi)\
**Post date:** [July 31, 2016, 7:55pm UTC](https://forum.getkirby.com/t/question-about-validate-max/4840/2 "2016-07-31T19:55:45Z")

</div>

Hi @sandbox  
If you want to validate the maximum length of a text field you have two options:  
max = number of characters or value if only numeric characters.  
maxwords = number of words

I hope this makes sense!  
Read more about validators in the docs here: [https://getkirby.com/docs/cheatsheet/#validators](https://getkirby.com/docs/cheatsheet/#validators)

NOTE: this post was edited to avoid misleading users coming here from another search.

---

<div class="post-metadata">

**Author:** ![sandbox](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/sandbox/32/2615_2.png) [@sandbox](https://forum.getkirby.com/u/sandbox)\
**Post date:** [July 31, 2016, 8:11pm UTC](https://forum.getkirby.com/t/question-about-validate-max/4840/3 "2016-07-31T20:11:02Z")

</div>

Hi @Thiousi

Thank you for the explanation but unfortunately doesn’t seems correct.

If I use `max: 21` then I can see a counter in the upper right corner above the text field. And if I use `size: 21` I get no counter and the same error (Can’t save the page.) when I enter only digits.

Did you tried it? You shoud 😉

---

<div class="post-metadata">

**Author:** ![Thiousi](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thiousi/32/13656_2.png) [@Thiousi](https://forum.getkirby.com/u/Thiousi)\
**Post date:** [July 31, 2016, 8:18pm UTC](https://forum.getkirby.com/t/question-about-validate-max/4840/4 "2016-07-31T20:18:16Z")

</div>

Huh that’s interesting! I can’t test this right now but I’ll give it a shot tomorrow!

Looking at the code [https://github.com/getkirby/toolkit/blob/7a26c83a9e22b4d71a6d4f646152de94e434cdc8/lib/v.php#L99](https://github.com/getkirby/toolkit/blob/7a26c83a9e22b4d71a6d4f646152de94e434cdc8/lib/v.php#L99)

---

<div class="post-metadata">

**Author:** ![Thiousi](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thiousi/32/13656_2.png) [@Thiousi](https://forum.getkirby.com/u/Thiousi)\
**Post date:** [July 31, 2016, 8:21pm UTC](https://forum.getkirby.com/t/question-about-validate-max/4840/5 "2016-07-31T20:21:06Z")

</div>

[Ah I found it!](https://github.com/getkirby/toolkit/blob/94d1d6e14698e73f5c5deb7cc3400d4426e7137b/helpers.php#L207)  
The size() function used in max() checks if the value is numeric and in this case returns its value instead of its length.

I think it’s safe to say this is by design. I’ll let the support crew confirm.

Note: If a title is mix characters, you’re safe with max!  
I’mm editing my first post given that I was completely wrong and don’t want to mislead people 🙂

---

<div class="post-metadata">

**Author:** ![sandbox](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/sandbox/32/2615_2.png) [@sandbox](https://forum.getkirby.com/u/sandbox)\
**Post date:** [July 31, 2016, 8:27pm UTC](https://forum.getkirby.com/t/question-about-validate-max/4840/6 "2016-07-31T20:27:28Z")

</div>

Ah interesting!

I had already figured it out, that if I add any other character than a digit then it works. It’s a rare case but if you want a titel or in my case a menu item with only digits then you run into it. 😁

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [July 31, 2016, 8:27pm UTC](https://forum.getkirby.com/t/question-about-validate-max/4840/7 "2016-07-31T20:27:31Z")

</div>

The way I see it, I would expect the field to check the string length even if it just consisted of numbers, so I’d regard this as a bug.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [July 31, 2016, 8:29pm UTC](https://forum.getkirby.com/t/question-about-validate-max/4840/8 "2016-07-31T20:29:52Z")

</div>

I created [an issue on GitHub](https://github.com/getkirby/panel/issues/899).

---

<div class="post-metadata">

**Author:** ![Thiousi](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thiousi/32/13656_2.png) [@Thiousi](https://forum.getkirby.com/u/Thiousi)\
**Post date:** [July 31, 2016, 8:30pm UTC](https://forum.getkirby.com/t/question-about-validate-max/4840/9 "2016-07-31T20:30:04Z")

</div>

This is debatable… I think that separating the length and value would be a better option to give more flexibility. Thoughts?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [July 31, 2016, 8:32pm UTC](https://forum.getkirby.com/t/question-about-validate-max/4840/10 "2016-07-31T20:32:29Z")

</div>

If you want to validate a number, you should use a number field. IMHO, a text field is a string, so it should check string length. Although we might need another validator.

---

<div class="post-metadata">

**Author:** ![Thiousi](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thiousi/32/13656_2.png) [@Thiousi](https://forum.getkirby.com/u/Thiousi)\
**Post date:** [July 31, 2016, 8:34pm UTC](https://forum.getkirby.com/t/question-about-validate-max/4840/11 "2016-07-31T20:34:12Z")

</div>

maxlength and minlength would be more obvious.

I’m trying to think of cases where a text field could be used for a number. I think a few can come up.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [July 31, 2016, 8:36pm UTC](https://forum.getkirby.com/t/question-about-validate-max/4840/12 "2016-07-31T20:36:23Z")

</div>

Well, these cases are probably not that numerous, but think of years as titles, 1984 or whatever.

---

<div class="post-metadata">

**Author:** ![Thiousi](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thiousi/32/13656_2.png) [@Thiousi](https://forum.getkirby.com/u/Thiousi)\
**Post date:** [July 31, 2016, 8:39pm UTC](https://forum.getkirby.com/t/question-about-validate-max/4840/13 "2016-07-31T20:39:07Z")

</div>

You’re right I think! It doesn’t look like the validators have an understanding of the type of field they’re in. Or am I missing something?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [July 31, 2016, 8:40pm UTC](https://forum.getkirby.com/t/question-about-validate-max/4840/14 "2016-07-31T20:40:29Z")

</div>

Exactly, the validator does not take into account the type of field it validates but only the value of the field.

---

<div class="post-metadata">

**Author:** ![Thiousi](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thiousi/32/13656_2.png) [@Thiousi](https://forum.getkirby.com/u/Thiousi)\
**Post date:** [July 31, 2016, 8:44pm UTC](https://forum.getkirby.com/t/question-about-validate-max/4840/15 "2016-07-31T20:44:40Z")

</div>

Alright! I love digging into the code to understand what causes the issue like that. Mostly because the Kirby code is easy to read. I would never have done that with another CMS… Thanks for walking along 😉

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [July 31, 2016, 9:02pm UTC](https://forum.getkirby.com/t/question-about-validate-max/4840/16 "2016-07-31T21:02:37Z")

</div>

I’ll mark this as solved as we have found the cause of the issue and there is now an issue on GitHub.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [August 1, 2016, 10:18am UTC](https://forum.getkirby.com/t/question-about-validate-max/4840/17 "2016-08-01T10:18:13Z")

</div>

As this will not be fixed before Kirby 2.4, you could write your own [custom validator](https://getkirby.com/docs/developer-guide/objects/validators).

Edit: Lukas will try to add this to 2.3.2.

---

<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:** [August 1, 2016, 11:04am UTC](https://forum.getkirby.com/t/question-about-validate-max/4840/18 "2016-08-01T11:04:42Z")

</div>

And done. Kirby 2.3.2 will be published this week and it will contain the fix for this. Just in time. 🙂

Please note that you need to change your blueprint to benefit from the new behavior:

```auto
  title:
    label: Title
    type: text
    validate:
      maxLength: 21

```

---

<div class="post-metadata">

**Author:** ![sandbox](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/sandbox/32/2615_2.png) [@sandbox](https://forum.getkirby.com/u/sandbox)\
**Post date:** [August 1, 2016, 11:41am UTC](https://forum.getkirby.com/t/question-about-validate-max/4840/19 "2016-08-01T11:41:40Z")

</div>

Thank you in advance! 😀 But why is it a good idea to fix it with a new term, one with an uppercase character in it? I’m only curious.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [August 1, 2016, 11:45am UTC](https://forum.getkirby.com/t/question-about-validate-max/4840/20 "2016-08-01T11:45:23Z")

</div>

The current max validator is used for both text and number fields, it is field type agnostic. Therefore, we need a new validator for strings only. CamelCase is for readability.

[Next page](https://forum.getkirby.com/t/question-about-validate-max/4840.md?page=2)
