All docs
V19.1
24.1
The page you are viewing does not exist in version 24.1.
23.2
The page you are viewing does not exist in version 23.2.
23.1
The page you are viewing does not exist in version 23.1.
22.2
The page you are viewing does not exist in version 22.2.
22.1
The page you are viewing does not exist in version 22.1.
21.2
The page you are viewing does not exist in version 21.2.
21.1
The page you are viewing does not exist in version 21.1.
20.2
The page you are viewing does not exist in version 20.2.
20.1
The page you are viewing does not exist in version 20.1.
19.2
19.1
18.2
18.1
17.2
A newer version of this page is available. Switch to the current version.

jQuery Validator - 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.

View Demo

See Also

comparisonTarget

Specifies the function whose return value is used for comparison with the validated value.

Type:

Function

Return Value:

Object

A value to be compared with the validated value.

The rule is valid if the validated value is equal to the return value of the comparisonTarget function.

NOTE
The operator specified by the comparisonType option is used for comparison.

comparisonType

Specifies the operator to be used for comparing the validated value with the target.

Type:

String

Default Value: '=='
Accepted Values: '!=' | '!==' | '<' | '<=' | '==' | '===' | '>' | '>='

Use the ComparisonOperator enum to specify this option when the widget is used as an ASP.NET MVC 5 Control or a DevExtreme-Based ASP.NET Core Control. This enum accepts the following values: Equal, NotEqual, StrictEqual, NotStrictEqual, GreaterThan, GreaterThanOrEqual, LessThan, and LessThanOrEqual.

ignoreEmptyValue

If set to true, empty values are valid.

Type:

Boolean

Default Value: false

message

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

Type:

String

Default Value: 'Values do not match'

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 or not the rule should be always checked for the target value or only when the target value changes.

Type:

Boolean

Default Value: true

type

Specifies the type of the current rule.

Type:

String

Accepted Values: 'required' | 'numeric' | 'range' | 'stringLength' | 'custom' | 'compare' | 'pattern' | 'email'

Set this field to "compare" to define a rule that will be broken if the validated value does not equal to the return value of the specified comparisonTarget function.