Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
90
rated 0 times [  94] [ 4]  / answers: 1 / hits: 19750  / 12 Years ago, wed, january 2, 2013, 12:00:00

I have a kendo date picker that is constructed as follows:



$(#date).kendoDatePicker({
format: yyyy-MM-dd,
footer: ,
parseFormats: [MM/dd/yyyy, dd/MM/yyyy]
});


I would like to use the kendo validator to validate that the date contains a valid date in the format of yyyy-MM-dd. I have tried this:



<input type=date id=date placeholder=yyyy-mm-dd name=date required data-required-msg=Please enter a date. data-date-msg=Please enter a valid date./>


While the validator does correctly validate the required condition, it does not seem to validate that the date is in the correct format or is a valid date. For instance, abc passes as a valid date as does 2013-18-85. How can I use the validator to ensure a valid date in the correct format?


More From » validation

 Answers
3

If you want to validate a date you need to define a rule (no built-in rule).



Try defining:



$(#date).kendoValidator({
rules: {
date: function (input) {
var d = kendo.parseDate(input.val(), yyyy-MM-dd);
return d instanceof Date;
}
}
});


NOTE: Remember that KendoUI first uses parseFormats option for parsing the date, then converts it to the format option and finally run validations. That's why I use in validation yyyy-MM-dd and not [MM/dd/yyyy, dd/MM/yyyy].


[#81126] Monday, December 31, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
susanajamiep

Total Points: 466
Total Questions: 113
Total Answers: 108

Location: Liberia
Member since Fri, Oct 22, 2021
3 Years ago
susanajamiep questions
Sun, Jun 12, 22, 00:00, 2 Years ago
Mon, Mar 7, 22, 00:00, 2 Years ago
Wed, Jun 10, 20, 00:00, 4 Years ago
Fri, Jan 24, 20, 00:00, 4 Years ago
;