Validation Rules

This section lists validation rules that can be used within the dxValidator.

CompareRule

A validation rule that demands that a validated editor has a value that is equal to a specified expression.

Type:

Object

To specify the expression that the validated field must match, set the rule's comparisonTarget configuration option. Assign a function to this option. The validated value will be compared to the function's return value. The comparison will be performed by using the operator that is set for the comparisonType option.

Show Example:
AngularJS
Knockout
jQuery

In this example, the 'compare' rule is applied to the 'Confirm your password' editor. This rule demands that the value of this editor equals to the value specified within the 'Password' editor. To check this rule, specify different passwords in the editors.


                                    

                                    

In this example, the 'compare' rule is applied to the 'Confirm your password' editor. This rule demands that the value of this editor equals to the value specified within the 'Password' editor. To check this rule, specify different passwords in the editors.


                                    

                                    

In this example, the 'compare' rule is applied to the 'Confirm your password' editor. This rule demands that the value of this editor equals to the value specified within the 'Password' editor. To check this rule, specify different passwords in the editors.


                                    

                                    

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.


                                    

                                    

EmailRule

A validation rule that demands that the validated field match the Email pattern.

Type:

Object

Show Example:
AngularJS
Knockout
jQuery

In this example, the 'email' rule is applied to the 'Email' editor. This rule demands that the editor value match the Email pattern. To check this rule, specify a wrong email.


                                    

                                    

In this example, the 'email' rule is applied to the 'Email' editor. This rule demands that the editor value match the Email pattern. To check this rule, specify a wrong email.


                                    

                                    

In this example, the 'email' rule is applied to the 'Email' editor. This rule demands that the editor value match the Email pattern. To check this rule, specify a wrong email.


                                    

                                    

NumericRule

A validation rule that demands that the validated field has a numeric value.

Type:

Object

Show Example:
AngularJS
Knockout
jQuery

In this example, the 'numeric' rule is applied to the editor. This rule demands that the editor has a numeric value. To check this rule, specify a string in the editor.


                                    

                                    

In this example, the 'numeric' rule is applied to the editor. This rule demands that the editor has a numeric value. To check this rule, specify a string in the editor.


                                    

                                    

In this example, the 'numeric' rule is applied to the editor. This rule demands that the editor has a numeric value. To check this rule, specify a string in the editor.


                                    

                                    

PatternRule

A validation rule that demands that the validated field match a specified pattern.

Type:

Object

To specify the regular expression that the validated field must match, set the rule's pattern configuration option.

Show Example:
AngularJS
Knockout
jQuery

In this example, the 'pattern' rule is applied to the 'Login' editor. This rule demands that the editor value has no digits. To check this rule, use digits when specifying a login.


                                    

                                    

In this example, the 'pattern' rule is applied to the 'Login' editor. This rule demands that the editor value has no digits. To check this rule, use digits when specifying a login.


                                    

                                    

In this example, the 'pattern' rule is applied to the 'Login' editor. This rule demands that the editor value has no digits. To check this rule, use digits when specifying a login.


                                    

                                    

RangeRule

A validation rule that demands the target value be within the specified value range (including the range's end points).

Type:

Object

To specify the range that the validated value must match, set the rule's min and max configuration options. Note that the specified range can be on a date-time or numeric scale. To validate a value against a string length, use the stringLength rule.

Show Example:
AngularJS
Knockout
jQuery

In this example, the 'range' rule is applied to the editor. This rule demands that the editor value be within 25 and 35. To check this rule, specify a value out of this range.


                                    

                                    

In this example, the 'range' rule is applied to the editor. This rule demands that the editor value be within 25 and 35. To check this rule, specify a value out of this range.


                                    

                                    

In this example, the 'range' rule is applied to the editor. This rule demands that the editor value be within 25 and 35. To check this rule, specify a value out of this range.


                                    

                                    

RequiredRule

A validation rule that demands that a validated field has a value.

Type:

Object

Use this rule type to ensure the target editor value is specified. The rule will be broken in the following cases.

  • If the validated value is null.
  • If the specified value has a type that is not expected for the target field (e.g., a string for the DateBox widget).
Show Example:
AngularJS
Knockout
jQuery

StringLengthRule

A validation rule that demands the target value length be within the specified value range (including the range's end points).

Type:

Object

To specify the range that the validated value length must match, set the rule's min and max configuration options.

NOTE
This rule validates string values or the values that can be cast to a string.
Show Example:
AngularJS
Knockout
jQuery

In this example, the 'stringLength' rule is applied to the 'Password' editor. This rule demands that the editor value length be from 4 to 6 symbols. To check this rule, specify a password with a length out of this range.


                                    

                                    

In this example, the 'stringLength' rule is applied to the 'Password' editor. This rule demands that the editor value length be from 4 to 6 symbols. To check this rule, specify a password with a length out of this range.


                                    

                                    

In this example, the 'stringLength' rule is applied to the 'Password' editor. This rule demands that the editor value length be from 4 to 6 symbols. To check this rule, specify a password with a length out of this range.