I have a case statement below where it checks for a file type in a file input which works correctly:
function imageValidation(imageuploadform) {
var val = $(imageuploadform).find(".fileImage").val();
switch(val.substring(val.lastIndexOf('.') + 1).toLowerCase()){
case 'gif':
case 'jpg':
case 'jpeg':
case 'pjpeg':
case 'png':
return true;
default:
$(imageuploadform).find(".fileImage").val();
// error message here
alert("To upload an image, please select an Image File");
return false;
}
return false;
}
Now what happens is that if it matches one of the case statements then it returns true and by default it returns an alert which I want to use if file input is blank.
But how can I display this alert:
alert("Image File Type is Incorrect. Must be either: \n (jpg, jpeg, pjpeg, gif)")
If the file input does not match with one of the file type cases above?
Simply create an empty case and it should work! The default case will catch everything hence catching your non-desired extensions!