Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kaushal's avatar

Can anyone give example of confirm password validation?? I am using following way but not working properlly.

$arr_validation["rules"] = array(
    "password"              => "required|confirmed",
    "password_confirmation" => "required",
);
            
$arr_validation["rules_messages"] = array(
    "password.required"                 => "Please Enter password",
    "password_confirmation.required"    => "Please Enter Confirm Password",
    "password.confirmed"                => "Confirm password does not metch with password!",
);

$validator = validator::make($arr_form_data, $arr_validation["rules"], $arr_validation["rules_messages"]);
0 likes
6 replies
devfrey's avatar

What do you mean by "not working properly"?

kaushal's avatar

@DEVFREY - I have entered same text in password and confirm password textbox though it is giving "Confirm password does not metch with password!" error message

devfrey's avatar

I suggest you double-check your form's HTML. Maybe you have a spelling error in your template.

vandan's avatar

@KAUSHAL - try this

"password" => "required|confirmed",
"password_confirmation" => "required|same:password",
munazzil's avatar

@kaushal If you are used the confirmed in the password it call the password_confirmation as well, use as like below and check,

$arr_validation["rules"] = array(
"password"              => "required",
"password_confirmation" => "confirmed",
);

$arr_validation["rules_messages"] = array(
"password.required"                 => "Please Enter password",
"password.confirmed"                => "Confirm password does not metch with password!",
);
martinbean's avatar

@munazzil That won’t work. If you have the following rule:

return [
    'password_confirmation' => 'confirmed',
];

Then Laravel is going to check the value of password_confirmation matches the value of a field named password_confirmation_confirmation.

Docs: https://laravel.com/docs/master/validation#rule-confirmed

@kaushal Your validation should look like this:

return [
    'password' => ['required', 'string', 'confirmed'],
];

This will check:

  • There’s a valid for a field named password.
  • The value of password matches the value of a field named password_confirmation.

If that’s not working, check what data is actually being passed to your controller:

dd($request->input());

A good candidate for writing a test ;)

2 likes

Please or to participate in this conversation.