1

I want to validate the file format.

How can i allow the user to upload only .xls file in jquery.

I am using uploadfy plugin to upload the file

Regards showreddy

user1071753
  • 391
  • 1
  • 3
  • 6

2 Answers2

2

Although this question was answered up top, you can bind a submit function to check the file by performing this below ->

$("#my_form").bind("submit", function(){
  var ext = $('#my_file_field').val().split('.').pop().toLowerCase();
  if($.inArray(ext, ['xls']) == -1) {
    alert('invalid extension!');
  }
});

This question was asked previously over at ->

How to have jQuery restrict file types on upload?

Community
  • 1
  • 1
Ohgodwhy
  • 49,779
  • 11
  • 80
  • 110
1

You could set the option of uploadfy 'fileExt' : '*.xls'

But there is no way you can validate a file, that you are currently uploading to the server.

mas-designs
  • 7,498
  • 1
  • 31
  • 56