Skip to content

Commit f0c3dbb

Browse files
committed
Fixing merge issues.
2 parents abff7d8 + de53feb commit f0c3dbb

File tree

8 files changed

+44
-0
lines changed

8 files changed

+44
-0
lines changed

after:1986-05-28

Whitespace-only changes.

after:1986-28-05,

Whitespace-only changes.

application/language/en/validation.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"countbetween" => "The :attribute must have between :min and :max selected elements.",
3737
"countmax" => "The :attribute must have less than :max selected elements.",
3838
"countmin" => "The :attribute must have at least :min selected elements.",
39+
"date_format" => "The :attribute must have a valid date format.",
3940
"different" => "The :attribute and :other must be different.",
4041
"email" => "The :attribute format is invalid.",
4142
"exists" => "The selected :attribute is invalid.",

before:1986-05-28

Whitespace-only changes.

before:1986-28-05,

Whitespace-only changes.

laravel/documentation/validation.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,14 @@ Many times, when updating a record, you want to use the unique rule, but exclude
205205

206206
> **Note:** The **before** and **after** validation rules use the **strtotime** PHP function to convert your date to something the rule can understand.
207207
208+
#### Validate that a date attribute conforms to a given format:
209+
210+
'start_date' => 'date_format:H\\:i'),
211+
212+
> **Note:** The backslash escapes the colon so that it does not count as a parameter separator.
213+
214+
The formatting options for the date format are described in the [PHP documentation](http://php.net/manual/en/datetime.createfromformat.php#refsect1-datetime.createfromformat-parameters).
215+
208216
<a name="rule-email"></a>
209217
### E-Mail Addresses
210218

laravel/tests/cases/validator.test.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,28 @@ public function testExistsRule()
483483
$this->assertFalse(Validator::make($input, $rules)->valid());
484484
}
485485

486+
/**
487+
* Tests the date_format validation rule.
488+
*
489+
* @group laravel
490+
*/
491+
public function testTheDateFormatRule()
492+
{
493+
$input = array('date' => '15-Feb-2009');
494+
$rules = array('date' => 'date_format:j-M-Y');
495+
$this->assertTrue(Validator::make($input, $rules)->valid());
496+
497+
$input['date'] = '2009-02-15,15:16:17';
498+
$rules['date'] = 'date_format:"Y-m-d,H:i:s"';
499+
$this->assertTrue(Validator::make($input, $rules)->valid());
500+
501+
$input['date'] = '2009-02-15';
502+
$this->assertFalse(Validator::make($input, $rules)->valid());
503+
504+
$input['date'] = '15:16:17';
505+
$this->assertFalse(Validator::make($input, $rules)->valid());
506+
}
507+
486508
/**
487509
* Test that the validator sets the correct messages.
488510
*

laravel/validator.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,19 @@ protected function validate_after($attribute, $value, $parameters)
759759
return (strtotime($value) > strtotime($parameters[0]));
760760
}
761761

762+
/**
763+
* Validate the date conforms to a given format.
764+
*
765+
* @param string $attribute
766+
* @param mixed $value
767+
* @param array $parameters
768+
* @return bool
769+
*/
770+
protected function validate_date_format($attribute, $value, $parameters)
771+
{
772+
return date_create_from_format($parameters[0], $value) !== false;
773+
}
774+
762775
/**
763776
* Get the proper error message for an attribute and rule.
764777
*

0 commit comments

Comments
 (0)