Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

183
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda