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?

1

3 Answers 3

71

You could use the equalTo method:

$('#myform').validate({ rules: { email: 'required', emailConfirm: { equalTo: '#email' } } }); 
Sign up to request clarification or add additional context in comments.

4 Comments

can you tell how to add custom message for this?
Sure, use the messages attribute. I strongly suggest you to reading the documentation of the jquery validate plugin which contains all the necessary details: jqueryvalidation.org/documentation
@sreemanthpulagam Yep, see stackoverflow.com/questions/6777634/…
How to multiple for single input fields ?
24

You can also do this on the second field:

 class="required email" equalTo='#email' 

1 Comment

Does this need hte Jquery?
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> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.