I have the following jquery enabled javascript:
<form>
    <input type="file">
</form>
jQuery(function($) {
  $('form').delegate('input[type=file]', 'change', function() {
    var form = $(this).closest('form');
    form.append('<input type="file">');
  });
});
it will dynamically add a file upload field as the user add files they want to upload. how can I limit it to images only, and stop adding new fields after they've added 5 images?
I'm trying to switch from having numerous field, which I validated as images like so:
var valid_extensions = /(.gif|.jpg|.jpeg|.png)$/i;
function CheckExtension(fld){
  if (valid_extensions.test(fld.value)) return true;
  alert('only gif, png or jpg formats are allowed!');
  fld.select();
  fld.value="";
  fld.focus();
  return false;
}
<input type="file" onChange="return CheckExtension(this);">
 
     
    