1

I've got two input fields, email and email_confirm. The email field has the value of the users email from the database. I want to make sure if the user updates their email (both inputs have to have the same value) that they match, however, I can't use the defaul equalTo because email input always has a value. So I need to check if email_confirm is equalTo email IF the email value is different to the default value.

Here's the code I have, value seems to be empty always also.

$.validator.addMethod('myEqual', function (value, element, param){
        return value == $(param).val();
}, 'Message');
2
  • Solved with: $.validator.addMethod('myEqual', function (value, element, param){ return $(element).val() == $(param).val(); }, 'Message'); Commented Apr 26, 2011 at 15:49
  • answer your own question and mark as the answer, not unheard of Commented Apr 26, 2011 at 15:51

2 Answers 2

2

Just add the below rule for email_confirm field,

equalTo : "#email" //Replace #email with the id the of the email field.

No need to add custom method for that.

Sign up to request clarification or add additional context in comments.

Comments

0
if ($("#email").val() != theDefaultValue) {
  if ($("#email").val() == $("#email_confirm")) {
    // It's all good
  } else {
    // It's all bad
  }
} else {
  // It doesn't matter
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.