33

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?

Steven
  • 18,761
  • 70
  • 194
  • 296
  • 1
    http://stackoverflow.com/questions/931687/using-jquery-validate-plugin-to-validate-multiple-form-fields-with-identical-name – Zirak Feb 28 '11 at 20:57

3 Answers3

71

You could use the equalTo method:

$('#myform').validate({
    rules: {
        email: 'required',
        emailConfirm: {
            equalTo: '#email'
        }
    }
});
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
24

You can also do this on the second field:

 class="required email" equalTo='#email'
Jazzy
  • 6,029
  • 11
  • 50
  • 74
2

U can use this

email: {
      required: true, email: true
      },
c_email: { 
                required: true, equalTo: "#email", minlength: 5
          },

<div class="form-row"><span class="label">email</span><input type="email" name="email" class="required" id="email" /></div>

<div class="form-row"><span class="label">Confirm email</span><input type="email" name="c_email" id="c_email" /></div>
Naresh Kumar
  • 345
  • 3
  • 6