简体   繁体   English

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

[英]How to apply validation for Dynamically added fields

Iam using javascript validation methods and rules for my form.And it is working fine.But I have an option that user can add many phonenumbers using clicking on a button Add More .But how to validate those fields through javascript.Bec we did'nt know how many fields user can add...I have tried with 我为表单使用了javascript验证方法和规则,并且运行良好。但是我可以选择用户可以通过单击Add More按钮来添加许多电话号码,但是如何通过javascript验证这些字段。知道用户可以添加多少个字段...我尝试了

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

I need to give 2 diff messages for the both required fields.How can I achieve that.Thanks in advance. 我需要为两个必填字段提供2个差异消息,我该如何实现呢?

Maybe your have to call the addClassRules method after you added a new phonenumber field 添加新的电话号码字段后,可能必须调用addClassRules方法

Cheers 干杯

In that you can add html5 required attr to the generated input field inside the form that makes validation 这样,您可以将html5必需的attr添加到进行验证的表单内的生成的输入字段中

check this link also 还要检查此链接

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM