Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

187
Visualizações
Input File multiple Validation Javacript

It is possible to validate within a multiple Input file that one of the files is of type word (.doc, .docx) and another of type PDF (.pdf)?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I have a created a working codepen that shows you a javascript code which iterates over the files uploaded with the file upload input, and checks if their file extension is in pdf, doc or docx.

Though as others have mentioned in comments, checking file format in client-side is unsafe and you should double check on the server side.

Snippet below

function testFiles(){
        var fileInput = document.getElementById('upload');   
        // iterate over files
        for (let i = 0; i < fileInput.files.length; i++) {
            var filename = fileInput.files[i].name
            // get file extension
            var file_extension = filename.split('.').pop()
            if(file_extension == "pdf" 
               || file_extension == "doc"
               || file_extension == "docx"){
              alert(filename + ' is a .pdf, .doc or .docx file')
            }                 
            else alert(filename + ' is not an authorized file')
        }
}
 <input id="upload" type="file" onchange="testFiles()" multiple>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda