loose comparison or strict comparison in dateFormat validation method?

loose comparison or strict comparison in dateFormat validation method?

hzhonghzhong Posts: 26Questions: 9Answers: 0

Hello,

When using dateFormat validation as

->validator( Validate::dateFormat( 'Y' ) )

I found it does not report validation error if input is not in the format of ''Y A full numeric representation of a year, 4 digits''. I found it's because this line

For example, if the input is 11

$val = '11';
$format = 'Y';
$date = DateTime::createFromFormat($format, $val);
$date->format($format) == $val;

The above code uses loose comparison and evaluates True. Strict comparison would evaluate False and report validation error.

Replies

Sign In or Register to comment.