Knockout date validation not working correctly

前端 未结 3 1477
粉色の甜心
粉色の甜心 2021-01-22 03:54

I need to validate date in localized format (SK) and it is not possible with knockout validation.

I am using: Durandal 1.2.0 Knockout 2.3.0 Knockout validation https://g

3条回答
  •  执笔经年
    2021-01-22 04:19

    The only working solution I have for now is below. The problem with this validator is that it also validates default(EN) date format as valid, so I have to add a IF to return this as invalid date format.

    var dateValidator = function (val) {
                if (!val)
                    return false;
                if (moment(val, 'DD.MM.YYYY HH:mm').isValid()) {
                    return true;
                }
                else
                    return false;
            };

    var startDate = ko.observable().extend({ validation: { validator: dateValidator, message: 'Start of task is not in correct format.' } });

提交回复
热议问题