0

I'm trying to add file validation when a user selects a file to upload. The file type validation works fine but I'm unclear as to why the file size is not working. Does anyone have any ideas?

$('input[type=file]').change(function () {
var val = $(this).val().toLowerCase();
var regex = new RegExp("(.*?)\.(zip|bmp|jpg|jpeg|tif|pdf|cdr|gbr|gtl|dxf|dwg)$");
    if(!(regex.test(val))) {
       $(this).val('');
       $("#fileError").html("<span class='flash'>You are trying to upload an file format we do not accept, please refer to our <a target='_blank' href='http://uk-cpi.com/inkjet-flex/guides/design-guide'>Design Guidelines ➜</a> and upload an accepted file format.<br></span>");
    }

    if(val.size > 2097152) {
         $("#fileError").html("<span class='flash'>File size must under 2mb!</span>");
    }

});
Dan Lee
  • 684
  • 4
  • 15
  • 35

0 Answers0