Knockout date validation not working correctly

前端 未结 3 1478
粉色の甜心
粉色の甜心 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:08

    Very late for this, but just want to share my updates on @ChoptimusPrime's answer. Not hard-coding the format:

    ko.validation.rules['dateAndFormat'] = {
        validator: function (val, format) {
            return ko.validation.utils.isEmptyVal(val) || moment(val, format).isValid();
        },
        message: 'Please provide a valid date.'
    };
    ko.validation.registerExtenders();
    

提交回复
热议问题