jQuery Validation Plugin custom method always return invalid
<p>please help to find out issue with my jquery validation. I am using <a href="https://jqueryvalidation.org/" rel="nofollow">jQuery Validation plugin</a> for validate my form. I have added a custom rule for check dimension of an image(trying to upload image). Here is code for custom method</p>

<pre><code>$.validator.addMethod('checkDim', function (value, element, param) {     
    var image = new Image();
    var file = element.files[0];
    var _URL = window.URL || window.webkitURL;
    image.src = _URL.createObjectURL(file);
    image.onload = function () {
        console.log("The image width is " + this.width + " and image height is " + this.height);
        if(this.width == param[0] &amp;&amp; this.height == param[1]){ 
            return true;
        }
        else{            
            return false;
        }
    };  

}, 'Image dimension must be as specified');
</code></pre>

<p>I have added a rule like below</p>

<pre><code>image: {required: true, accept: "image/*", checkDim: [1366,311]}
</code></pre>

<p>function is called correctly as i can see message in console and also dimension is also calculate correctly but this function always return invalid.</p>

<p>Please help me to figure out what i am doing wrong.</p>