diff --git a/src/Rules/ValidJalaliDate.php b/src/Rules/ValidJalaliDate.php index 869dd00..550cde7 100644 --- a/src/Rules/ValidJalaliDate.php +++ b/src/Rules/ValidJalaliDate.php @@ -25,6 +25,10 @@ public function passes($attribute, $value) $date = explode($this->character, $value); + if (count($date) <= 1) { + return false; + } + return $this->checkValidDate(...$date); } diff --git a/tests/Rules/ValidJalaliDateTest.php b/tests/Rules/ValidJalaliDateTest.php index 96550af..7ca2329 100644 --- a/tests/Rules/ValidJalaliDateTest.php +++ b/tests/Rules/ValidJalaliDateTest.php @@ -79,4 +79,19 @@ public function jalali_date_is_correct_with_different_default_character() $this->assertTrue($passes); } + /** + * Test jalali date is not correct with different default character. + * + * @test + * + * @return void + */ + public function jalali_date_is_not_correct_with_different_default_character() + { + $rules = ['jalali_date' => [new ValidJalaliDate('-')]]; + $data = ['jalali_date' => '2016/15/25']; + $passes = $this->app['validator']->make($data, $rules)->passes(); + + $this->assertFalse($passes); + } }