Javascript validation of a multiple field

0

I'm having trouble validating the files of a input of type file that has an array and is also a multiple . As in the function below the variable filename only returns the name of the first file being there are 3 others or may be more. Has anyone gone through this?

 function envia(){

        var nomearquivo = document.getElementById('file').value;

        var valor = nomearquivo.split("-");

        var data = valor[0].slice(-8);

        var n = data.split("");

        var databr = n[0]+n[1]+'/'+n[2]+n[3]+'/'+n[4]+n[5]+n[6]+n[7];

       var valida = valida_data_novo(databr);

         if(valida){

    document.forms[0].submit();

    }

  }

  <INPUT TYPE="FILE" NAME="arquivo[]" ID="file" multiple/>
    
asked by anonymous 26.08.2014 / 19:40

1 answer

1

The validation for files is a little different I found several methods and managed to solve my problem.

  var fileInput = document.getElementById ("file");

  if ('files' in fileInput){

          for (var i = 0; i < fileInput.files.length; i++) {

              var file = fileInput.files[i];

              var file = file.name;

              var valor = file.split("-");

              var data = valor[0].slice(-8);

              var n = data.split("");

              var databr = n[0]+n[1]+'/'+n[2]+n[3]+'/'+n[4]+n[5]+n[6]+n[7];

              var valida = val_data_multiarq(databr,file);

          }
      }
    
26.08.2014 / 22:08