Saturday 31 October 2015

Validate passwords with Laravel 5.1

validate a password using following condition:

1) Password is at least 8 characters long

2) Password should contains at least 1 uppercase, 1 lowercase and 1 special character letter


  $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);
    }

No comments:

Post a Comment