Validator

A widget that is used to validate the associated DevExtreme editors against the defined validation rules.

Included in: dx.mobile.js, dx.web.js, dx.viz-web.js, dx.all.js
Module: ui/validator
Export: default

You can create the Validator widget using one of the following approaches.

jQuery
JavaScript
HTML
$(function() {
    $("#textBox1").dxTextBox({ })
        .dxValidator({
            validationRules: [
                // ...
            ]
        });
});
<div id="textBox1"></div>
Angular
HTML
<dx-text-box>
    <dx-validator>
        <dxi-validation-rule type="required" message="Value is required"></dxi-validation-rule>
    </dx-validator>
</dx-text-box>
AngularJS
HTML
<div dx-text-box="{ }"
        dx-validator="{
            validationRules: [
            // ...
        ]
    }">
</div>
Knockout
HTML
<div data-bind="dxTextBox: { },
    dxValidator: {
        validationRules: [
            // ...
        ]
    }">  
</div>

Note that DevExtreme widgets require you to link the jQuery library to your application. If you use the Knockout or AngularJS approach, the Knockout or AngularJS library is also required. For detailed information on linking these libraries to your project, refer to the topics in the Installation section.

See Also

The learn the validation rules that can be defined using the Validator widget for an editor, refer to the Validation Rules section.

The editors that are associated with the Validator widgets are automatically validated against the specified rules each time the event assigned to the editor's valueChangeEvent option occurs. In addition, several editors can be validated at once. To learn how to do this, refer to the Validate Several Editor Values topic.

See Also

View Demo Watch Video

Configuration

An object defining configuration options for the Validator widget.

Name Description
adapter

An object that specifies what and when to validate, and how to apply the validation result.

elementAttr

Specifies the attributes to be attached to the widget's root element.

height

Specifies the widget's height.

name

Specifies the editor name to be used in the validation default messages.

onDisposing

A handler for the disposing event. Executed when the widget is removed from the DOM using the remove(), empty(), or html() jQuery methods only.

onInitialized

A handler for the initialized event. Executed only once, after the widget is initialized.

onOptionChanged

A handler for the optionChanged event. Executed after an option of the widget is changed.

onValidated

A handler for the validated event.

validationGroup

Specifies the validation group the editor will be related to.

validationRules

An array of validation rules to be checked for the editor with which the dxValidator object is associated.

width

Specifies the widget's width.

Methods

This section describes members used to manipulate the widget.

Name Description
element()

Gets the root element of the widget.

focus()

Sets focus to the editor associated with the current Validator object.

instance()

Returns this widget's instance. Use it to access other methods of the widget.

off(eventName)

Detaches all event handlers from the specified event.

off(eventName, eventHandler)

Detaches a particular event handler from the specified event.

on(eventName, eventHandler)

Subscribes to a specified event.

on(events)

Subscribes to the specified events.

option()

Gets the widget's options.

option(optionName)

Gets a specific option value.

option(optionName, optionValue)

Assigns a new value to a specific option.

option(options)

Sets one or more options.

reset()

Resets the value and validation result of the editor associated with the current Validator object.

validate()

Validates the value of the editor that is controlled by the current Validator object against the list of the specified validation rules.

Events

This section describes events fired by this widget.

Name Description
disposing

Raised when the widget is removed from the DOM using the remove(), empty(), or html() jQuery methods only.

initialized

Raised only once, after the widget is initialized.

optionChanged

Raised after an option of the widget is changed.

validated

Fires after an editor value is validated against the specified validation rules.

See Also

Validation Rules

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