Validate if age is over 18 years old

前端 未结 6 2340
情歌与酒
情歌与酒 2020-12-14 12:23

Just wondering, can I do this to validate that a user has entered a date over 18?

//Validate for users over 18 only
function time($then, $min)
{
    $then =          


        
6条回答
  •  暖寄归人
    2020-12-14 13:00

    HTML Input:

     
    

    PHP code:

    function validateDateOfBirth($birthDay)
        {
    // convert user input date to string and +18 years;
    // compare user input date with current date;
    
            if (time() < strtotime('+18 years', strtotime($birthDay))) {
                return 'Not 18';
            }
            return "user is older than 18 years old";
        }
    

提交回复
热议问题