Correct alternative that implements a validator for a date field in Laravel

Asked

Viewed 1,038 times

2

to.

$this->validate($request, [
    'data_nascimento' => 'regex:ddmmyyyy',
]);

b.

$this->validate($request, [
    'data_nascimento' => 'required|date',
]);

c.

$this->validate($request, [
    'data_nascimento' => 'digits:8|integer',
]);

d.

$this->validate($request, [
    'data_nascimento' => 'datetime|null',
]);

I’m between A and B, I need help.

  • 1

    regex:ddmmyyyy is incorrect.

1 answer

2

I believe that this is the best, its date that comes from the screen is in Brazilian format, IE, day, month and year, utilize date_format in d/m/Y format:

$this->validate($request, [
    'data_nascimento' => 'required|date_format:"d/m/Y"',
]);

Reference: date_format:format

  • Thank you for the information.

  • @Pedrosoares your date is in Brazilian format? how is the format?

  • Yes, Brazilian format.

  • @Pedrosoares if it is the answer to your question, tick as answer!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.