I have input file with multiple attribute, now i want to validate the dimention. Here is my setup for jquery-validate
$("#AddForm").validate({
rules: {
'noteMedia[]': {
extension: "jpg|jpeg|png",
dimension:[1080,608],
},
},
messages: {
'noteMedia[]':{
extension: "Only image allowed" ,
dimension:"Image dimension Must 1080 * 608"
}
}
});
here is my custom validation
$.validator.addMethod('dimension', function(value, element, param) {
if(element.files.length == 0){
return true;
}
var no = 1;
Array.from(element.files).forEach(imageData => {
var fr = new FileReader;
fr.onload = function() {
var img = new Image;
img.onload = function() {
var width = img.width;
var height = img.height;
if(width > param[0] || height > param[1]){
return false;
}
};
img.src = fr.result;
};
fr.readAsDataURL(imageData);
i = i+1
console.log(i);
});
return true;
},'Please upload an image with 1080 x 608 pixels dimension');
My validation not working, the validation is not showing when i'm choose item with 1200*600
. How can i fix it ?