Jump to content

Confirm password without submit jquery


web_master

Recommended Posts

I can't find how can I validate (confirm) password width jQuery without submit. Mean, when I type the password confirmation to see immediatly is correct or not.

 

 

<input type="password" name="password" autocomplete="off" value="password" maxlength="12" />
<input type="password" name="password" autocomplete="off" value="passwordconfirm" maxlength="12" />

 

 

I can't find script without submit form....

Link to comment
Share on other sites

$("input[type='password']:eq(0)").on("change",function(){
var next = $("input[type='password']:eq(1)");
if(!next.val().trim()) return;
if(next.val()==$(this).val()) // passwords match, do something
$(next).addClass("correct-pass");
else
$(next).addClass("wrong-pass");
});
$("input[type='password']:eq(1)").on("change",function(){
var prev = $("input[type='password']:eq(0)");
if(!prev.val().trim()) return;
if(prev.val()==$(this).val())
$(this).addClass("correct-pass");
else
$(this).addClass("wrong-class");
});

It's just an example of how to implement that. There's some other ways, too.

Link to comment
Share on other sites

Maybe just use a function that checks both rather than two functions to check the same thing.

 

JSFiddle: http://jsfiddle.net/LKr8G/

 

// The input fields.
var inputs = $("input[type='password']");

// The output message element.
var output = $("span");

// Run the check as the password is typed.
inputs.keyup(check);

// On change, run the check.
inputs.change(check);

// Function to compare passwords.
function check()
{
	// Check if the fields' values are the same.
	if (inputs[0].value == inputs[1].value)
	{
		// Yay!  They match.
		output.html("Passwords match!").css("color", "#090");
	}
	else
	{
		// Let's tell them the bad news.
		output.html("Passwords do not match.").css("color", "#900");
	}
}
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.