使用Kendo UI验证验证特定字段/特定规则

时间:2015-05-26 09:53:31

标签: javascript validation kendo-ui kendo-validator

目前,我有以下自定义规则来验证表单的字段。

规则

$scope.validator = $("#frmPreregistration").kendoValidator({
    rules: {
        varifySsn: function (input) {
            var ret = true;
            if (input.is("[name=last4Ssn]") && $scope.Last4DigitsSsn != undefined ) {
                ret = $scope.validateSsnLast4Digit();
            }
            return ret;
        },
        varifyDob: function (input) {
            var ret = true;
            if (input.is("[name=dob]") && $scope.DateOfBirth != undefined ) {
                ret = $scope.validateDateOfBirth();
            }
            return ret;
        },
        varifyZipCode: function (input) {
            var ret = true;
            if (input.is("[name=zipCode]") && $scope.ZipCode != undefined ) {
                ret = $scope.validateZipCode();
            };
        return ret;
        }
    },
    messages: {
        varifySsn: $scope.resources.SsnLast4DigitDoesNotMatch,
        varifyDob: $scope.resources.DobNotMatchWithSelectedUserType,
        varifyZipCode: $scope.resources.ZipCodeNotMatchWithSelectedUserType,
    }
}).data("kendoValidator");

每当用户在$scope.validator.validate()

中的表单中的任何字段中输入值时,我都会验证表单

这导致在用户输入任何值之前触发所有字段的规则。

问题 我是否有可能一次运行特定的验证规则或运行特定字段的验证?

1 个答案:

答案 0 :(得分:3)

您可以将validateInput用于特定元素。

示例:

$scope.validator.validateInput($("input[name=dob]"));

隐藏无效邮件,您可以使用hideMessages功能

$scope.validator.hideMessages();