How to write a field in laravel that can pass the verification through one rule when there are multiple verification rules?
给我你的怀抱
给我你的怀抱 2017-05-16 16:48:29
0
2
601

How to write a field in laravel that can pass the verification through one rule when there are multiple verification rules?

'alipay'=>array('sometimes','required','email','regex:/^1(3[0-9]|4[57]|5[0-35-9] |7[0135678]|8[0-9])\d{8}$/'),

For example, this verification rule
As long as either the email account or mobile phone account passes, the verification can pass

给我你的怀抱
给我你的怀抱

reply all (2)
大家讲道理

I have encountered this kind of demand before, and I really didn’t find a native support solution in the documentation. This is what I did in the end, you can refer to it

$rule = preg_match('/^\d+$/', $request->input($this->loginUsername())) ? 'tel' : 'email'; $this->validate($request, [ $this->loginUsername() => "required|{$rule}", 'password' => 'required', ]);
    刘奇

    Custom validation rules

    //AppServiceProvider class AppServiceProvider extends ServiceProvider { public function boot() { Validator::extend('alipay', function($attribute, $value, $parameters, $validator) { return preg_match('/^1(3[0-9]|4[57]|5[0-35-9]|7[0135678]|8[0-9])\d{8}$/',$value) || filter_var(FILTER_VALIDATE_EMAIL,$value); }); } public function register() { } } // Controller 使用 'alipay' => ['required','alipay']
      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!