I have added a file upload to my asp.net website. However, I want to limit the file types that user can select. For example, I only the user to select mp3 files. How can I a
Use the following code js code for to only select the required file type which we want to select. IN the below example I want to select only zip file, On browse it only shows the zip file extension file name
(function ($) {
$.fn.acceptFileType = function (types) {
if (types == undefined) {
return true;
} else {
types = types.split(",")
}
this.each(function () {
$(this).bind("change", function () {
if (!$.inArray($(this).val().replace(/([\d\w.]+)(\.[a-z0-9]+)/i, '\2'), types)) {
$(this).val('');
return false;
}
return true;
});
});
};
})(jQuery);
$(":file").acceptFileType(".zip");