0

我有一个领域:

<input type="text" id="AlternateEmailaddress" name="AlternateEmailaddress" 
       value="" class="validate[custom[email],maxSize[50]] input25" 
       parent_tab="tab2">

这是自定义电子邮件验证规则:

"email": {
    // Shamelessly lifted from Scott Gonzalez via the Bassistance Validation plugin http://projects.scottsplayground.com/email_address_validation/
    "regex": /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,
    "alertText": "* Invalid email address"
},

这不是必需的,但是会触发电子邮件规则。

我在同一页面上也有密码和确认密码字段,它们不是必需的,它们的规则也会触发。

如果不需要此字段,我如何防止它这样做?

jsFiddle 问题演示:http: //jsfiddle.net/3Pge2/8/

4

1 回答 1

0

我有一个解决方法。我即时分配验证规则,如果值为空白,则将其删除。测试和工作。

$("#AlternateEmailaddress").change(function () {
if($("#AlternateEmailaddress").val().trim() != "") {
    $("#AlternateEmailaddress").addClass("validate[custom[email],maxSize[50]]")
    $("#my_info").validationEngine('validate');
} else {
    $("#AlternateEmailaddress").removeClass("validate[custom[email],maxSize[50]]")
}
}); 

更新小提琴:http: //jsfiddle.net/3Pge2/10/

于 2013-02-04T17:17:43.003 回答