title: JQuery Validate input file type
body: <p>I have a form that can have 0-hundreds of <code>&lt;input type="file"&gt;</code> elements. I have named them sequentially depending on how many are dynamically added to the page. </p>
  
  <p>For example:</p>
  
  <pre><code>&lt;input type="file" required="" name="fileupload1" id="fileupload1"&gt;
  &lt;input type="file" required="" name="fileupload2" id="fileupload2"&gt;
  &lt;input type="file" required="" name="fileupload3" id="fileupload3"&gt;
  &lt;input type="file" required="" name="fileupload999" id="fileupload999"&gt;
  </code></pre>
  
  <p>In my JQuery I want to validate these inputs on acceptable MIME/file type. Like this:</p>
  
  <pre><code>$("#formNew").validate({
      rules: {
          fileupload: {
              required: true, 
              accept: "image/jpeg, image/pjpeg"
          }
      }
  </code></pre>
  
  <p>Immediately my problem is that the <code>name</code> attribute of the input file elements is dynamic. It has to be dynamic so that my web application can deal with each upload correctly. So obviously using "fileupload" isn't going to work in the rules section.</p>
  
  <p>How do I set the rules for all inputs which have a name like "fileupload"?</p>
  
  <p>This is the code that dynamically adds the inputs:</p>
  
  <pre><code>var filenumber = 1;
  $("#AddFile").click(function () { //User clicks button #AddFile
      $('&lt;li&gt;&lt;input type="file" name="FileUpload' + filenumber + '" id="FileUpload' + filenumber + '" required=""/&gt; &lt;a href="#" class="RemoveFileUpload"&gt;Remove&lt;/a&gt;&lt;/li&gt;').prependTo("#FileUploader");
      filenumber++;
      return false;
  });
  $("#FileUploader").on('click', '.RemoveFileUpload', function () { //Remove input
      if (filenumber &gt; 0) {
          $(this).parent('li').remove();
          filenumber--;
      }
      return false;
  });
  </code></pre>