You need to create your custom validation method
$.validator.addMethod('dimention', function(value, element, param) {
if(element.files.length == 0){
return true; <--- check here if file not added than return true for not check file dimention
}
var width = $(element).data('imageWidth');
var height = $(element).data('imageHeight');
if(width == param[0] && height == param[1]){
return true;
}else{
return false;
}
},'Please upload an image with 1170 x 300 pixels dimension');
And you need to set parameter imageWidth and imageHeight at image change like this
// files is id of your input
<input type="file" id="files" name="name" />
$('#files').change(function() {
$('#files').removeData('imageWidth');
$('#files').removeData('imageHeight');
var file = this.files[0];
var tmpImg = new Image();
tmpImg.src=window.URL.createObjectURL( file );
tmpImg.onload = function() {
width = tmpImg.naturalWidth,
height = tmpImg.naturalHeight;
$('#files').data('imageWidth', width);
$('#files').data('imageHeight', height);
}
});
and call like this
rules: {
banner: {
dimention:[1170,300]
}
}
Working fiddle link fiddle link