range validation

3 posts, 0 answers
  1. JCSCo
    JCSCo avatar
    16 posts
    Member since:
    Jun 2014

    Posted 19 Sep 2014 Link to this post


    Hello,

    I am trying to validate a year range in a numeric text box in a grid. I am able to validate one end of the range, but not the other. For example, this works:

       validation: { custom:
              function (input) {
                     input.attr("data-custom-msg", "Year out of range");
                     return input.val() >= 1970; 
                    }
            }

    but when i try this:

       validation: { custom:
               function (input) {
                      input.attr("data-custom-msg", "Year out of range");
                       return input.val() >= 1970 || input.val() <= 2050;
                      }
            }

    it will not catch either end of the range. Is there a way to validate a range of numbers?

    Thanks
  2. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 23 Sep 2014 Link to this post

    Hi,

    The result of the condition:
    input.val() >= 1970 || input.val() <= 2050
    will be true for any number. You should use the && operator instead.

    Regards,
    Daniel
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Kendo UI is VS 2017 Ready
  4. JCSCo
    JCSCo avatar
    16 posts
    Member since:
    Jun 2014

    Posted 23 Sep 2014 in reply to Daniel Link to this post

    Thanks. Guess I didn't think that one all the way through.
Back to Top