all(), [ 'username' => ['required', 'string', 'min:3', 'max:20', 'regex:/^[a-zA-Z0-9]+[ _.-]?[a-zA-Z0-9]+$/i', 'unique:users'], 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'], 'password' => ['required', 'confirmed', Rules\Password::defaults()], ], [ 'username.min' => 'Username can only be 3 to 20 characters long.', 'username.max' => 'Username can only be 3 to 20 characters long.', 'username.regex' => 'Username must be alphanumeric and cannot begin or end with a special character. (a-z, 0-9, dot, hyphen, space, underscores are allowed)' ]); if ($validator->fails()) { return back()->withErrors($validator)->withInput(); } $user = User::create([ 'username' => $request->username, 'email' => $request->email, 'password' => Hash::make($request->password), ]); event(new Registered($user)); Auth::login($user); return redirect(RouteServiceProvider::HOME); } }