You are viewing limited content. For full access, please sign in.

Question

Question

How can I prevent two e-mail address from matching?

asked on May 18, 2015 Show version history

I am trying to use sample code from the help files to accomplish this task, but am not having any luck. Perhaps there is something interfering in one of the other Jquery lines I have written? Below is the full code.

This script is successfully hiding a Country, renaming "State / Province / Region" to just "State", and preventing zip code from being anything but 5 digits long. The last thing I need it to do is make sure that two e-mail address fields do not match; the fields are in classes "applicantemail" and "caoemail".

 

$(document).ready (function () {
  $(".Country").parent().children().val("USA");
  $(".Country").parent().children().css('display', 'none');
  $(".State").parent().children().val("TX");
  $(".State").siblings().text('State');
  
  $('.applicantemail, .caoemail').on('blur input', function () {
        if ($('.applicantemail input').val() == $('.caoemail input').val()) {
            $('.Submit').attr("disabled", "disabled");
            if ($('.warningText').length > 0 || $('.caoemail input').val() == ''){
                return; 
            } else {
                $('<p class="warningText">The email addresses you entered for the Applicant and Chief Administrative Officer must not be the same.</p>').insertAfter('.caoemail');
            }
        }
        else
            $('.warningText').remove();
        $('.Submit').removeAttr('disabled');
  
  var re = new RegExp("^\\d{5}$");
  
  $('.Postal').on('change', function() {
    var s = parseNumber($(this).val());
    $('p.zipWarning').remove();
    if (re.test(s)) {
      $('.Postal').val(s);
      $('.Submit').removeAttr('disabled');
    } else {
      $('.Postal').val("0");
      $('<p class="zipWarning">Please enter a 5 digit zip code.</p>').insertAfter('.Postal');
      $('.Submit').attr('disabled', true);
    }
  });
  
  function parseNumber(n) {
    var f = parseFloat(n); //Convert to float number.
    return isNaN(f) ? 0 : f; //treat invalid input as 0;
  }
  
  
  
})

Note: the first e-mail field with class .applicantemail is inside a table with 1 fixed row, so it lays out the information better. Not sure if this impacts.

 

0 0

Answer

APPROVED ANSWER SELECTED ANSWER
replied on May 18, 2015

It seems like you're missing some braces in your email if else statement. Try

$(document).ready (function () {
  $(".Country").parent().children().val("USA");
  $(".Country").parent().children().css('display', 'none');
  $(".State").parent().children().val("TX");
  $(".State").siblings().text('State');
  
  $('.applicantemail, .caoemail').on('blur input', function () {
    if ($('.applicantemail input').val() == $('.caoemail input').val()) {
      $('.Submit').attr('disabled', true);
      if ($('.warningText').length > 0 || $('.caoemail input').val() == ''){
        return; 
      } else {
        $('<p class="warningText">The email addresses you entered for the Applicant and Chief Administrative Officer must not be the same.</p>').insertAfter('.caoemail');
      }
    } else {
      $('.warningText').remove();
      $('.Submit').removeAttr('disabled');
    }
  });
  
  var re = new RegExp("^\\d{5}$");
  
  $('.Postal').on('change', function() {
    var s = parseNumber($(this).val());
    $('p.zipWarning').remove();
    if (re.test(s)) {
      $('.Postal').val(s);
      $('.Submit').removeAttr('disabled');
    } else {
      $('.Postal').val("0");
      $('<p class="zipWarning">Please enter a 5 digit zip code.</p>').insertAfter('.Postal');
      $('.Submit').attr('disabled', true);
    }
  });
  
  function parseNumber(n) {
    var f = parseFloat(n); //Convert to float number.
    return isNaN(f) ? 0 : f; //treat invalid input as 0;
  }

})
1 0
replied on May 18, 2015

Alex got it.

Also, I'd suggest adding another warning text above the Submit button that describes why it is disabled. That way, if the user doesn't notice the first one and scrolls down to submit, they don't get confused.

0 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.