Check all extensions from a multiple upload file input

html, javascript

Solution

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.

var selection = document.getElementById('file');
for (var i=0; i<selection.files.length; i++) {
    var ext = selection.files[i].name.substr(-3);
    if(ext!== "mp4" && ext!== "m4v" && ext!== "fv4")  {
        alert('not an accepted file extension');
        return false;
    }
} 

Problem

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 /> ```

Original source