check upload img extension jquery

Solutions on MaxInterview for check upload img extension jquery by the best coders in the world

showing results for - "check upload img extension jquery"
Mckayla
25 Aug 2020
1<input type="file" id="image" accept="image/*" onChange="validate(this.value)"/>
2
3function validate(file) {
4    var ext = file.split(".");
5    ext = ext[ext.length-1].toLowerCase();      
6    var arrayExtensions = ["jpg" , "jpeg", "png", "bmp", "gif"];
7
8    if (arrayExtensions.lastIndexOf(ext) == -1) {
9        alert("Wrong extension type.");
10        $("#image").val("");
11    }
12}
13