validate the selected date

3 posts, 1 answers
  1. David
    David avatar
    17 posts
    Member since:
    Jul 2012

    Posted 01 Aug 2012 Link to this post

    i wish to validate the contents of the datetime picker to ensure the date they selected is older than 18 years.. i.e for a date of birth, ensure the user is over 18 years old.
    how do i add this validation layer to it? using the kendovalidator, it performs the validation on clicking the calender button which obviously wont work because the validated value is empty (or the previous value)

  2. Answer
    Iliana Nikolova
    Iliana Nikolova avatar
    2622 posts

    Posted 06 Aug 2012 Link to this post

    Hello David,

    I have already replied to your other forum thread on the same subject. For convenience I am pasting my reply here as well:

    You could set a custom validation rules via the rules property of the Kendo UI Validator. For example: 

    Copy Code
    <div id="MyForm">
           <input id="datepicker" required />
       $(document).ready(function() {
            rules: {
              custom: function(input){

    Regarding the behavior you have observed ("the validation is triggered on clicking the date calendar button") - I tried to reproduce it, but to no avail. In order to assist you best please provide some more details or even best a small but runnable project which illustrates your scenario. Thank you in advance for your cooperation. 

    Iliana Nikolova
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Atlas
    Atlas avatar
    97 posts
    Member since:
    Jun 2009

    Posted 07 Nov 2014 in reply to David Link to this post

    I have been pretty disgusted with the validation on the kendo datepicker. What good is validation if it doesn't work regardless of the way the data is input. The validation works great if you use the calendar icon to pick your date, but provides no validation if you hand type in a value.
    I have been complaining about this for some time, and the solution I got from Telerik was a cluster. I was having to use a lot of extra code to make it work.
    Well I finally got around to investigating custom code attributes, both server side and client side, and discovered that it is quite easy to add a custom code attribute that works on both the client and the server side. You have to create a class that handles both scenarios, and you have to write some custom javascript, but once you get the hang of it, it's really easy.
    We have requirements on several of our date values that they are on or before today or on or after today, so I created two attributes:
    1) DateTimeMaxNowAttribute
    2) DateTimeMinNowAttribute
    I will attach the files for all of this. One of the namespaces you will need is the one that supports: ModelClientValidationRule apparently, from what I am reading this used to be in a different namespace, but I you are using MVC 4 or later, this rule exists in the System.Web.WebPages namespace.
    use the code  in the attached files and simply decorate your property like so:

            [DisplayName("Estoppel Request Date")]
            [DisplayFormat(DataFormatString = "{0:d}")]
            public DateTime? EstoppelRequestDate { get; set; }

Back to Top