This doesn't work:
datetime:required:isValidDate=^Y-m-d H:i^
The difference is that isDate() is a native formit validator and isValidDate is a custom validator.
Step to reproduce
This is my custom Validator:
<?php
if(!function_exists('isValidDate')){
function isValidDate(string $date, string $format = 'Y-m-d'){
// php
$dateObj = DateTime::createFromFormat($format, $date);
return $dateObj && $dateObj->format($format) == $date;
}
}
$value = trim($value); // The value of the field that was POSTed.
$param = trim($param) // For some reason I always get a blank space at the end of the param string
// empty dates should be filtered by :required
if(empty($value)) return true;
// Standard Format for date validation
if(empty($format)) $format = 'Y-m-d';
$isValidDate = isValidDate($value,$param);
if($isValidDate === true){
return true;
}
else {
if(!empty($key)){
$validator->addError(
$key
,'String must have this format: "' . $param . '"'
);
}
return false;
}
Observed behavior
And this is what I get as an error message:
For some reason "Y-m-d H:i" turns into "Y-m-d H".
I suspect that the validator function splits each validation line by ":" and then processes each part individually.
If there is a ":" inside the param part of a validator, the validator gets only part of the original string.
Expected behavior
This might be tricky. I guess there is an explode(':', $string) somewhere at work. It would have to ignore ":" inside he param part (^.H:i^).
Environment
I guess this problem is not related to server, php , or a software version.
Bug report
Summary
This works:
This doesn't work: datetime:required:isValidDate=^Y-m-d H:i^
The difference is that isDate() is a native formit validator and isValidDate is a custom validator.
Step to reproduce
This is my custom Validator:
Observed behavior
And this is what I get as an error message:
For some reason "Y-m-d H:i" turns into "Y-m-d H".
I suspect that the validator function splits each validation line by ":" and then processes each part individually.
If there is a ":" inside the param part of a validator, the validator gets only part of the original string.
Expected behavior
This might be tricky. I guess there is an explode(':', $string) somewhere at work. It would have to ignore ":" inside he param part (^.H:i^).
Environment
I guess this problem is not related to server, php , or a software version.