Ben
Ben

Reputation: 6086

jQuery-Validation-Engine - Custom funcCall validation causes error when value is empty

I have a custom validation function to verify that two password fields match using jQuery-Validation-Engine:

<input type="password" class="validate[required,funcCall[checkPassordMatch],maxSize[25]]"...

But if the field is not populated, and the form is submitted, I get the following exception:

Uncaught TypeError: Cannot read property 'checkPassordMatch' of undefined 

Is there any way I can only run this validation only if the input is populated, or if "required" passes first?

For reference, my function is as follows:

    // Validate the passwords match
function checkPassordMatch(field, rules, i, options){
    console.log(field + ' : ' + rules + ' : ' + i  + ' : ' + options )

    if (field.val() != jQuery("#inputPassword").val()) {
        return options.allrules.passwordMatch.alertText;
    }
}

Appreciate any thoughts.

Upvotes: 2

Views: 3145

Answers (1)

Ben
Ben

Reputation: 6086

This custom function is not needed. I can use:

validate[required,equals[password]]

Upvotes: 0

Related Questions