From a40aabbb05805cbbc7ea3a755f0131787b09e749 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Fri, 7 Sep 2012 14:02:04 +0200 Subject: [PATCH] Implement date_format validation rule. --- application/language/en/validation.php | 1 + laravel/validator.php | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/application/language/en/validation.php b/application/language/en/validation.php index e5116996..47bf151e 100644 --- a/application/language/en/validation.php +++ b/application/language/en/validation.php @@ -36,6 +36,7 @@ return array( "countbetween" => "The :attribute must have between :min and :max selected elements.", "countmax" => "The :attribute must have less than :max selected elements.", "countmin" => "The :attribute must have at least :min selected elements.", + "date_format" => "The :attribute must have a valid date format.", "different" => "The :attribute and :other must be different.", "email" => "The :attribute format is invalid.", "exists" => "The selected :attribute is invalid.", diff --git a/laravel/validator.php b/laravel/validator.php index ab446860..8b41ffc6 100644 --- a/laravel/validator.php +++ b/laravel/validator.php @@ -758,6 +758,19 @@ class Validator { return (strtotime($value) > strtotime($parameters[0])); } + /** + * Validate the date conforms to a given format. + * + * @param string $attribute + * @param mixed $value + * @param array $parameters + * @return bool + */ + protected function validate_date_format($attribute, $value, $parameters) + { + return date_create_from_format($parameters[0], $value) !== false; + } + /** * Get the proper error message for an attribute and rule. *