From 52091bda5fbc049758fd80a5b9c18ef13549629b Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 21 Mar 2012 13:40:52 -0500 Subject: [PATCH] Added "match" validation rule for regular expression checks. --- application/language/en/validation.php | 1 + laravel/validator.php | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/application/language/en/validation.php b/application/language/en/validation.php index 8c230f21..8285f1e9 100644 --- a/application/language/en/validation.php +++ b/application/language/en/validation.php @@ -36,6 +36,7 @@ "in" => "The selected :attribute is invalid.", "integer" => "The :attribute must be an integer.", "ip" => "The :attribute must be a valid IP address.", + "match" => "The :attribute format is invalid.", "max" => array( "numeric" => "The :attribute must be less than :max.", "file" => "The :attribute must be less than :max kilobytes.", diff --git a/laravel/validator.php b/laravel/validator.php index 4d6d1683..77ac724a 100644 --- a/laravel/validator.php +++ b/laravel/validator.php @@ -611,6 +611,18 @@ protected function validate_alpha_dash($attribute, $value) return preg_match('/^([-a-z0-9_-])+$/i', $value); } + /** + * Validate that an attribute passes a regular expression check. + * + * @param string $attribute + * @param mixed $value + * @return bool + */ + protected function validate_match($attribute, $value, $parameters) + { + return preg_match($parameters[0], $value); + } + /** * Validate the MIME type of a file upload attribute is in a set of MIME types. *