File Upload Validation using Jquery

Feb 10 2016 4:40 AM
I am trying to upload the images with the extension jpg,png&gif. When I am using the following code I am able to upload png and gif images but unable to upload jpg images. Please Help me Out. 
 
$.validator.addMethod("uploadfile",function(val,element){
var size=element.files[0].size;
console.log;
if(size > 1048576) {
console.log("returning false");
return false;
}
else {
console.log("returning true");
return true;
}
});
 rules{
<%=fu.UniqueID%>:{
required:true,
accept:".jpg?g|.png|.gif",
uploadfile:true,
},
},
messages{ 
<%=fu.UniqueID%>:{
required:"Please Upload Image",
accept:"File should be JPG, GIF or PNG",
uploadfile:"File Size must be less than 1MB"
},
 },

Answers (1)