Skip to content

Allow only pdf,doc,docx files for uploading with Jquery ?

Now if we want allow only pdf,doc, docx format files for file uploading, use the below code

Html


JQuery Script

if($('#file').val() != '') {            
      $.each($('#file').prop("files"), function(k,v){
          var filename = v['name'];    
          var ext = filename.split('.').pop().toLowerCase();
          if($.inArray(ext, ['pdf','doc','docx']) == -1) {
              alert('Please upload only pdf,doc,docx format files.');
              return false;
          }
      });        
}
1 1 vote
Article Rating
Subscribe
Notify of
guest

0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments