最低年龄验证幼虫 [英] minimum Age validation laravel

查看:82
本文介绍了最低年龄验证幼虫的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想验证用户的信息(例如出生日期),因为我在验证中使用了以下声明行,但是如何使其动态化,以便用户的最小年龄可以为13岁以下,所以无法注册?

I want to validation a users information like date of birth for that i have used following line of statement in validation, But how do i make it dynamic so users minimum age could be 13. below that can't register?

  return Validator::make($data, [
            'first_name' => 'required|string|max:255',
            'last_name' => 'required|string|max:255',
            'email' => 'required|string|email|max:255|unique:users',
            'password' => 'required|string|min:6',
            'date_of_birth' =>'required|date|before:2011-06-08',
        ]);

推荐答案

根据 https:/上的文档/laravel.com/docs/5.5/validation ,您应该能够使用与strtotime()函数一起使用的任何有效字符串.在这种情况下, strtotime('13 years ago') 是您所追求的动态日期的有效描述符.因此,以下方法应该起作用:

According to the docs at https://laravel.com/docs/5.5/validation, you should be able to use any valid string that works with the strtotime() function. In this case strtotime('13 years ago') is a valid descriptor for the dynamic date you are after. Hence, the following should work:

return Validator::make($data, [
    'first_name' => 'required|string|max:255',
    'last_name' => 'required|string|max:255',
    'email' => 'required|string|email|max:255|unique:users',
    'password' => 'required|string|min:6',
    'date_of_birth' =>'required|date|before:13 years ago',
]);

这篇关于最低年龄验证幼虫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆