Laravel 5 validate date as php Y format e.g 2015?

1.1k views Asked by At

I have a form that uses bootstraps datepicker. I want to collect the year as 2015 for example

How do i do that?

The datepicker code is this:

$('#manufacture_year').datepicker({
    format: " yyyy",
    viewMode: "years",
    minViewMode: "years",
    endDate: FromendDate,
    autoclose: true,
    disableEntry: true
});

I'm displaying the datepicker like so:

{!! Form::text('manufacture_year', null, ['placeholder' => '1984', 'class' => 'form-control datepicker-default', 'id' => 'manufacture_year']) !!}

My validation rules are:

'manufacture_year' => 'required|date|date_format:Y'

When i submit the form i keep getting:

The manufacture year is not a valid date.,The manufacture year does not match the format Y.

I put 'Y' as the date format refering to:

http://php.net/manual/en/function.date.php

Where it states that 'Y' equates a full numeric representation of a year, 4 digits

Thank you for reading this.

1

There are 1 answers

2
arkhamDev On

With @JoelHinz advice, i've changed my rules array to look like so

'manufacture_year' => 'required|date_format:Y'

And it works.