Javascript validation of an Multiple field

Asked

Viewed 172 times

0

I’m having trouble validating the files of a input of the kind file which has an array and is also a multiple. As in the function below the variable appointing just give me back the name of the first file and there are other 3 or may even be more. Someone has already 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/>

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);

          }
      }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.