Back
Validate passwords with Laravel 5.1
October 31, 2015

Validate passwords with Laravel 5.1

Posted on October 31, 2015  • 2 minutes  •Laravel 5.1

Validate password using following condition:

  • Password is atleast 8 characters long
  • Password should contains atleast 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);
}

Follow me

I work on web development using Javascript.