Match two fields with jQuery validate plugin

Steven picture Steven · Feb 28, 2011 · Viewed 29.5k times · Source

I have an e-mail field, and a confirm e-mail field. I need to validate both of them to make sure their values match.

Is there a way to add a rule to match those two fields?

Answer

Darin Dimitrov picture Darin Dimitrov · Feb 28, 2011

You could use the equalTo method:

$('#myform').validate({
    rules: {
        email: 'required',
        emailConfirm: {
            equalTo: '#email'
        }
    }
});