CustomRule

A validation rule with custom validation logic.

Type: Object

To specify the function that will validate the target value, use the rule's validationCallback configuration option.

NOTE
You can use the 'custom' rule for remote scenarios.
See Also
Show Example:
AngularJS
Knockout
jQuery

In this example, the 'custom' rule is applied to the 'Password' editor. This rule demands that the length of the editor value equals to or more than 4. To check this rule, specify a password with a length less than 4.


                                    

                                    

In this example, the 'custom' rule is applied to the 'Password' editor. This rule demands that the length of the editor value equals to or more than 4. To check this rule, specify a password with a length less than 4.


                                    

                                    

In this example, the 'custom' rule is applied to the 'Password' editor. This rule demands that the length of the editor value equals to or more than 4. To check this rule, specify a password with a length less than 4.


                                    

                                    

message

Specifies the message that is shown for end-users if the current rule is broken.

Type: String
Default Value: 'Value is invalid'

You do not have to specify this field. In this instance, a default message will be shown. To include the name of the validated editor into the default validation message as a subject, set the name field of the dxValidator object.

If you assign an empty string to the message field, the message will not be shown.

reevaluate

Indicates whether the rule should be always checked for the target value or only when the target value changes.

Type: Boolean
Default Value: false

type

Specifies the type of the current rule.

Type: String
Accepted Values: 'custom'

Set this field to 'custom' to define a rule that will be broken as a result of custom validation performed by the validationCallback function.

validationCallback

A function that validates the target value.

Type: function
Function parameters:
options: Object
An object defining validation parameters.
Object structure:
value: String|Number
The validated value.
rule: Object
The current rule object that exposes user-defined options, the isValid and message fields, and the rule type specific fields.
validator: Object
The dxValidator object that caused the validation.
Return Value: true|false
A Boolean value that indicates whether the validated value is valid against the checked rule.