Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

Laravel validating birthdate by 13 years old

$dt = new CarbonCarbon();
$before = $dt->subYears(13)->format('Y-m-d');

$rules = [
    ...
    'dob' => 'required|date|before:' . $before
];

---------------
  
Different Solution (Enhanced)

use CarbonCarbon;

        $dt = new Carbon();
        $before18Years = $dt->subYears(18)->format('Y-m-d');


            'birthdate' => [
                'date_format:' . config('panel.date_format'),
                'required',
                'before:'.$before18Years,
            ],

file panel.php

<?php

return [
    'date_format'         => 'Y-m-d',
    'time_format'         => 'H:i:s',
    'primary_language'    => 'en',
];

Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Laravel #validating #birthdate #years
ADD COMMENT
Topic
Name
2+5 =