IE麻烦 - 在Jquery中复杂的电话号码错误检查

时间:2012-06-25 14:42:08

标签: javascript jquery validation

我正在编写一段代码来验证三个电话号码。逻辑是,其中一个数字必须有效,否则代码的第3行会出错。除了IE之外,它的效果非常好。 IE没有检测到错误。此代码中的任何部分是否在IE中无法正常工作?

  //check first homephone
//check second workphone
//check third cellphone
// if nothing = 10 then something is wrong
var numLengthHome = ($('.homephone > .validPhone:eq(0)').val().length) + ($('.homephone > .validPhone:eq(1)').val().length) + ($('.homephone > .validPhone:eq(2)').val().length);
var numLengthWork = ($('.workphone  > .validPhone:eq(0)').val().length) + ($('.workphone  > .validPhone:eq(1)').val().length) + ($('.workphone  > .validPhone:eq(2)').val().length); var numLengthCell = ($('.cellphone > .validPhone:eq(0)').val().length) + ($('.cellphone > .validPhone:eq(1)').val().length) + ($('.cellphone > .validPhone:eq(2)').val().length);

var num1 = true; var num2 = true; var num3 = true; // all assume the numbers are fine until proven otherwise

 if ((($('.homephone > .validPhone:eq(0)').val()) && ($('.homephone > .validPhone:eq(1)').val()) && ($('.homephone > .validPhone:eq(2)').val()) && (numLengthHome == 10))) {
 $('.cellphone > .validPhone:eq(2)').parents('.formgroup').addClass('error');
 num1 = false;      
} 
else if ((($('.workphone > .validPhone:eq(0)').val()) && ($('.workphone > .validPhone:eq(1)').val()) && ($('.workphone > .validPhone:eq(2)').val()) && (numLengthWork == 10))) {
 $('.cellphone > .validPhone:eq(2)').parents('.formgroup').addClass('error'); 
num2 = false; 
  } else if ((($('.cellphone > .validPhone:eq(0)').val()) && ($('.cellphone > .validPhone:eq(1)').val()) && ($('.cellphone > .validPhone:eq(2)').val()) && (numLengCell == 10))) {
 $('.cellphone > .validPhone:eq(2)').parents('.formgroup').addClass('error'); num3 = false;
} else {
 $('.cellphone > .validPhone:eq(2)').parents('.formgroup').removeClass('error');
        }

 if((num1 == true) || (num2 == true) || (num3 == true)) {       
 $('.cellphone > .validPhone:eq(2)').parents('.formgroup').removeClass('error');

 }

HTML:

 <tr>
<td class="label_col indent">
      <div class="label">
        Home Phone:
       </div>
    </td>
    <td>
        <div id="ucRelatedContentControls_ctl01_divHomePhone" class="formgroup homephone">
            <input name="ucRelatedContentControls$ctl01$txtHomePhone1" maxlength="3" id="ucRelatedContentControls_ctl01_txtHomePhone1" class="input_10 input_stacked validPhone" type="text"><span class="pipe">-</span>
            <input name="ucRelatedContentControls$ctl01$txtHomePhone2" maxlength="3" id="ucRelatedContentControls_ctl01_txtHomePhone2" class="input_10 input_stacked validPhone" type="text"><span class="pipe">-</span>
            <input name="ucRelatedContentControls$ctl01$txtHomePhone3" maxlength="4" id="ucRelatedContentControls_ctl01_txtHomePhone3" class="input_10 input_stacked validPhone" type="text">


            <div class="tooltip">
                <div class="tooltip_arrow">
                </div>
                <div class="tooltip_message">
                    ipsum. Lorem ipsum dolor sit amet, consectetur adipiscing elit ...
                </div>
            </div>

             <div class="invalid">
                <div class="invalid_arrow">
                </div>
                <div class="invalid_message">
                    Error message
                </div>
            </div>
        </div>
    </td>
</tr>

(不要介意表 - 不在我正在做的项目范围内)。

0 个答案:

没有答案