1

我在我的项目中使用剑道日期选择器。Kendo 支持用户编辑日期,它也允许自由文本。如何防止用户输入除日期之外的任何内容。

4

1 回答 1

1

你有两个我知道的选项来解决这个问题。

选项1:

创建自定义验证器: http: //docs.telerik.com/kendo-ui/framework/validator/overview

选项 2:

在保存或数据更改时,您可以检查日期是否真正有效(我已将其包装在自己的实用程序类中,因此 JQuery 不在我的视图模型中):


function isValidDateTimePickerDate(id, allowNullsOrBlank) {
/// <summary>Examines the date in a Telerik date time picker to see if it is valid.</summary>
/// <param name="id" type="string">A string that represents the element's id (assumes it is prefixed with # -- my utility does not assume this, but I've condensed it for this post)</param>
/// <param name="allowNullsOrBlank" type="boolean">Indicates if a null is valid</param>
if (allowNullsOrBlank == null) {
    allowNullsOrBlank = true;
}

var value = $(id).val();

// Allow the user to have null or blank?
if (value == null || value.length === 0) {
    return allowNullsOrBlank;
}

var date = kendo.parseDate(value);
if (!date) {
    return false;
}

// Dates prior to 1900 are not valid and dates lower than 1753 
// will throw database exceptions in SQL Server
if (date.getFullYear() < 1900) {
    return false;
}

return true;
};
于 2015-10-05T22:01:52.913 回答