我想验证密码,以便符合以下条件:
目前我有:
$validator = \Validator::make($request, [
'password' => 'min:8|confirmed'
],[
'password.confirmed' => 'Both `password` and `password_confirmation` are required',
'password.min' => 'The password must contain at least 8 characters'
]);
这将照顾最小长度和确认,但我可以找到一个很好的方法来做其他检查。任何帮助将不胜感激。
答案 0 :(得分:2)
我认为你可以用正则表达式来做这个伎俩: http://laravel.com/docs/5.1/validation#rule-regex
您可以这样使用:
['password' => ['regex:^(?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=!?]).*$']]
希望它有所帮助!
答案 1 :(得分:0)
试试这个有效:)
$rules = array(
'username' => 'required',
'email' => 'required | between:5,100 | email ',
'password' => 'required | confirmed |regex:/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*()+]+.*)[0-9a-zA-Z\w!@#$%^&*()+]{8,}$/'
);
$input = Input::all();
$validation = Validator::make($input, $rules);
if ($validation->fails()){
//if validation fails redirect with inputs
return redirect()->route('/')->withInput()
->withErrors($validation);
}