验证器:该值必须等于所需的值

时间:2015-12-03 06:25:30

标签: php laravel laravel-5

如何在验证阶段检查传递的值是否等于我想要的值。

$rules = [
            'email' => 'required|email|max:255|unique:users',
            'password' => 'required|min:6',
            'admin_code' => 'required|<the value must be equals to this code "admin">',
        ];

1 个答案:

答案 0 :(得分:1)

假设您要确保 admin_code 始终等于 admin ,您可以使用这样的laraval验证器:

  

正则表达式:/ ^([a-z])+ $ / i字段值必须与提供的常规值匹配   表达

$rules = [
        'email' => 'required|email|max:255|unique:users',
        'password' => 'required|min:6',
        'admin_code' => 'required|regex:^admin$>',
    ];        
  

In:small,medium,large确保该值包含在   提供的值列表。

$rules = [
        'email' => 'required|email|max:255|unique:users',
        'password' => 'required|min:6',
        'admin_code' => 'required|in:admin>',
    ];
  

http://laravelbook.com/laravel-input-validation/