A simple date format mm/dd/yyyy validation is all I need...
$rules = array(
'renewal_date' => array('required', 'date_format:?')
);
What do I set the date format to? The Laravel documentation could be so much better.
Documentation is pretty clear to me, you should use
date_format:format
"The field under validation must match the format defined according to the date_parse_from_format PHP function."
Looking at it: http://php.net/manual/en/function.date-parse-from-format.php, I see you can do something like this:
$rules = array(
'renewal_date' => array('required', 'date_format:"m/d/Y"')
);
This is pure PHP test for it:
print_r(date_parse_from_format("m/d/Y", "04/01/2013"));
You can also do it manually in Laravel to test:
$v = Validator::make(['date' => '09/26/13'], ['date' => 'date_format:"m/d/Y"']);
var_dump( $v->passes() );
To me it's printing
boolean true
I got a similar problem, but with a d/m/Y date format. In my case, the problem was that I defined both "date" and "date_format" rules for the same field:
public static $rules = array(
'birthday' => 'required|date|date_format:"d/m/Y"',
...
The solution is to remove the "date" validator: you must not use both. Like this:
public static $rules = array(
'birthday' => 'required|date_format:"d/m/Y"',
...
after that, all is well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With