Invalid() Kirby function, can we check date format?

Can we validate a date format with the invalid() function?

Something like:

$data = ['date' => $date];
$rules = ['date' => array( 'required' , 'date' => 'mm/dd/yyyy' )];
$messages = ['date' => array( 'A date is required', 'The date format must be mm/dd/yyyy.' )];
$invalid = invalid( $data, $rules, $messages);

It seems to works partially.


Return false as expected



Return true

@gillesvauvarin have you tested if the v::date() method works as expected?

The v::date() method only checks for a valid date, not for a particular date format. E.g.if you do a dump

dump(date_parse('12/31')); // date_parse is use inside the v::date validator

…you get an array like this:

    [year] => 
    [month] => 12
    [day] => 31
    [hour] => 
    [minute] => 
    [second] => 
    [fraction] => 
    [warning_count] => 0
    [warnings] => Array

    [error_count] => 0
    [errors] => Array

    [is_localtime] => 

So I think you would need a custom validator to check the date format, rather than using the default date validator that just checks if the given date is a valid date in the sense of date_parse

Even the Kirby3 Date format 1999-06-25 is not valid? :slight_smile:

$data = array(
	'strasse'       => esc(get('strasse')),
	'plz'           => esc(get('plz')),
        'ort'           => esc(get('ort')),
        'mobile'        => esc(get('mobile')),
        'geburtstag'    => esc(get('geburtstag')),
$rules = array(
	'plz'           => array('min' => 1000, 'max' => 9999 ),
        'mobile'        => array('required', 'min' => 9),
        'geburtstag'    => array('required', 'date'), 

Or am I doing something wrong?

Doesn’t date need a format?

I just checked the Referenz…

Yeah, right. Hm…

Just tested and works for me, no error and message gets send.

I also tested a date format like 21.10.2019 and it validates as well.

You are right! It was another bug in the code! :grimacing:

Hello @texnixe, i would also like to validate a date format with the invalid() function?
I tried several solutions without success, and i am still not sure,
if it is possible to use the invalid-method to correctly validate dates from a form-input.
How did you format the german date in your example?

$rules = [
    'name' => ['required', 'min' => 3],
    'email' => ['required', 'email'],
    'birthday' => ['required', 'date' => '']

if i dump the date, i don’t get any errors,
but the invalid alert contains an error.

name and email are working as expected.
Do you suggest a custom-validation for dates?


I don’t think you can validate the date format with V::date(), if you look at the source code, you’ll see that all the validator does is check if the given string can be parsed as a date:

So if you want to check a particular format, I’d check against a regex pattern. V::match should do the job for these cases:

ok, to validate for the particular format ‘’ i changed the rule to:

'dob' => ['required', 'match' => '/^([0-9]{1,2})\\.([0-9]{1,2})\\.([0-9]{4})$/']

After the date-format is valid i will check if the date ist valid with php checkdate
tnx @texnixe

mhm. I’m working on a page with ajax-communication and I have a [page].json.php-file that does that magic.

SO when testing the form-input I always get the date-field returned as incorrect.

This is what I send as date: 2021-03-31
(it’s actually formatted by the browsers input type=“date”-field)
And that is exactly, what I get back, together with the “invalid”-message.

Here is the code from the json.php-file:

  $data = [
      'record_id'  => get('record_id'),
      'datum'  => get('datum'),

  $rules = [
      'record_id'  => ['required', 'integer'],
      'datum'  => ['required', 'date'],

  $messages = [
      'datum'  => 'Datumsformat inkorrekt: '.get('datum'),
  if($invalid = invalid($data, $rules, $messages)) 
      echo json_encode($invalid);

Can I expect to have a date-string like that accepted by invalid()?
If not, why?

kind regards,

Such a data string should actually validate, which you can test with


It does validate if I use it in plain page-template. But still not in my JSON-representation.
Tried switching date-formats


No difference …

Might be, there is a misbehaviour of invalid(), while v::date() works correctly?

I just tested both functions in the page-template:

<?= dump(V::date('2021-03-31')); ?>
<?= dump(invalid(["datum"=>"2021-03-30"],["datum"=>['date']],["datum"=>'Datum falsch'])); ?>

That is the result:

(why is the output doubled?)

So V::date checks ok while invalid() returns an error …

I think there is a bug in the validator, or in the way the helper passes the data to the validator.

Because there are two arguments passed, so the validator doesn’t go into the simple date validation, so the second part of this if statement

 if (is_int($value) !== true || is_int($test) !== true) {



hard to believe a problem with a standard validation like that has not been detected earlier.
But I’m glad it will be fixed soon.