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

    HTML
    JavaScript
    <div id="textBox1"></div>
    $(function() {
        $("#textBox1").dxTextBox({ })
            .dxValidator({
                validationRules: [
                    // ...
                ]
            });
    });
  • 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 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 height of the widget.

name

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

onDisposing

A handler for the disposing event.

onInitialized

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

onOptionChanged

A handler for the optionChanged event.

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 width of the widget.

Methods

This section describes members used to manipulate the widget.

Name Description
element()

Returns the root HTML element of the widget.

focus()

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

instance()

Returns an instance of this component class.

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()

Returns the configuration options of this component.

option(optionName)

Gets the value of the specified configuration option of this component.

option(optionName, optionValue)

Sets a value to the specified configuration option of this component.

option(options)

Sets one or more options of this component.

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

Fires when the widget is being removed.

initialized

Raised only once, after the widget is initialized.

optionChanged

Fires after an option of the component is changed.

validated

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

Validation Rules

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