如何为动态添加的字段应用验证

时间:2013-10-25 08:37:28

标签: javascript jquery validation

我使用javascript验证方法和规则为我的表单。它工作正常。但我有一个选项,用户可以通过点击按钮Add More添加许多phonenumbers。但如何通过JavaScript验证这些字段.Bec我们不知道用户可以添加多少字段...我已尝试过

jQuery.validator.addClassRules({
    'phneClass' : {
         required:true,
         numeric : true
     },
     'name' : {
         required : true
     } 
});

我需要为两个必填字段提供2条差异消息。如何实现这一点。提前谢谢。

2 个答案:

答案 0 :(得分:0)

在添加新的phonenumber字段

之后,可能需要调用addClassRules方法

干杯

答案 1 :(得分:0)

您可以将html5必需的attr添加到进行验证的表单内生成的输入字段

检查此链接

http://www.the-art-of-web.com/html/html5-form-validation/

http://www.wufoo.com/html5/attributes/09-required.html