Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

186
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!