I need to change this code so that the condition checks the file extensions of all the selected files from multiple select file input, this code only checks for one. Any way I can do this?
var file = document.getElementById('file');
var ext = file.value.substring(file.value.lastIndexOf('.') + 1);
if(ext!== "mp4" && ext!== "m4v" && ext!== "f4v") {
alert('not an accepted file extension');
return false;
}
<input id="file" name="uploaded[]" type="file" multiple />
Note I only bothered to get the last three characters of the string because you only have three letter file extensions. If you wanted you could use
.split('.')to get an array of segments and choose the last element of that array.