ajax jquery组验证

时间:2010-02-01 21:02:36

标签: jquery ajax validation

这是我的代码:

groups: {
    phone: "phone1-phone2-phone3"
   digits: true
},
errorPlacement: function(error, element) {
    if (element.attr("name") == "phone1" 
           || element.attr("name") == "phone2" || element.attr("name") == "phone3")
        error.insertAfter("#telephone");
    else
    error.insertAfter(element);
},
debug:true

这是我的表单输入文本:

<p><label for="name"><span class="red">*</span>Phone: </label> <input type="text" name="phone1" id="phone1" size="3" tabindex="12" />-<input type="text" name="phone2" id="phone2" size="3" tabindex="12" />-<input type="text" name="phone3" id="telephone" size="4" tabindex="12" /></p>

以上没有验证?任何想法都非常感谢!

1 个答案:

答案 0 :(得分:0)

组中的输入ID必须由不是-的空格分隔。这是code

$("#form").validate({
groups: {
  phone: "phone1 phone2 telephone"
},
rules: {
  phone1 : "digits",
  telephone : "digits",
  phone2 : "digits"
},
onsubmit: false,
errorPlacement: function(error, element) {
    if (element.attr("name") == "phone1"
           || element.attr("name") == "phone2" || element.attr("name") == "phone3")
        error.insertAfter("#telephone");
    else
    error.insertAfter(element);
},
debug:true
});

规则需要在规则选项

下指定