Validation with custom rules failing

2 posts, 0 answers
  1. cra
    cra avatar
    16 posts
    Member since:
    Jun 2012

    Posted 23 Mar Link to this post


    I have a validator set up on my form. I have several fields listed as required with data-required-message attributes to display specific messages.

    I also have a custom rule to compare two password fields to make sure they are the same:


            validateOnBlur: true,
            rules: {
                passwordmismatch: function (input) {
                    if ('[data-passwordmismatch-msg]')) {
                        var password = $.trim($password.val());
                        var password2 = $.trim($password2.val());
                        return (password === password2);
        var validator = $'kendoValidator');


    $frmCreateUser.submit(function (event) {
            if (validator.validate()) {
            } else {


    What is happening is even when all of the required rules pass and the password mismatch rule returns true, the validator still returns false. If I remove the custom rule everything works fine.

    Any help would be greatly appreciated.

  2. Dimiter Topalov
    Dimiter Topalov avatar
    313 posts

    Posted 25 Mar Link to this post

    Hi Christopher,

    The custom rule function should return true in the cases when the if condition false, otherwise the function will return undefined, which is in turn evaluated to false:

    rules: {
    passwordmismatch: function (input) {
    if ('[data-passwordmismatch-msg]')) {
    return true;

    The following links contain the corresponding section of our documentation and a demo:

    I hope this helps.

    Dimiter Topalov
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top