Hello Developers, I am trying to validate my image file format using the below code.
fileName(e) {
let selected = e.target.files;
for (let i = 0; i < selected.length; i++) {
if(selected[0]['type']!=='image/jpeg' || selected[0]['type']!=='image/png')
{
alert("Invalid File");
return false;
}
//console.log(selected[0]['type'])
this.file_names.push(e.target.files[i]);
this.file_name_deails.push(e.target.files[i].name);
//console.log(e.target.files[i].name);
}
But if I use following code only for jpeg it works
if(selected[0]['type']!=='image/jpeg' )
{
alert("Invalid File");
return false;
}
If I use || condition like below it doesn’t work. only show alert and return false.
if(selected[0]['type']!=='image/jpeg' || selected[0]['type']!=='image/png')
{
alert("Invalid File");
return false;
}
what is the issue here ? Thank you in advanced