使用jquery使用动态字段验证表单

i'm using Jquery validate plugin to validate a form.

I fill my form dynamically using php.. for example:

<form name="my_form" id="my_form">
   <label for="static_field_1">Insert static field 1</label>
   <input type="text" name="static_field_1" id="static_field_1"/>
   <label for="static_field_2">Insert static field 2</label>
   <input type="text" name="static_field_2" id="static_field_2" />

   <?php
      $no_dynamic_field = count($dynamic_fields_array);
      if($no_dynamic_field>0){
         for($i=0;$i<$no_dynamic_field;$i++){
   ?>
         <label for="dynamic_field_<?php echo $i;?>">Insert field <?php echo $dynamic_fields_array[$i];?></label> 
         <input type="text" name="dynamic_field_<?php echo $i;?>" id="dynamic_field_<?php echo $i;?>" />
   <?php
         }
      }
   ?>
</form>

I have to validate this form.. so for static field there is no problem:

$('#my_form').validate({
   rules: {
      static_field_1:"required",
      static_field_2:"required"
   },
   messages:{
      static_field_1:"Static field 1 required!",
      static_field_2:"Static field 2 required!",
   }
});

but how can i loop through dynamic field to validate them?

Thanks to everybody!

you can use:

$(document).ready(function(){
    $('#my_form').validate();
});

and put class='required' on every input.So your code will be:

<form name="my_form" id="my_form">
   <label for="static_field_1">Insert static field 1</label>
   <input type="text" name="static_field_1" id="static_field_1" class='required'/>
   <label for="static_field_2">Insert static field 2</label>
   <input type="text" name="static_field_2" id="static_field_2" class='required'/>

   <?php if(count($dynamic_fields_array)>0)
      for($i=0;$i<count($dynamic_fields_array);$i++){
   ?>
      <label for="dynamic_field_<?php echo $i;?>">Insert field <?php echo $dynamic_fields_array[$i];?></label> 
      <input type="text" name="dynamic_field_<?php echo $i;?>" id="dynamic_field_<?php echo $i;?>" class='required'/>
   <?php
      }
   ?>
   <?php }?>
</form>