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

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

  • jQuery
    Apply the dxValidator jQuery plug-in to an editor instance.

    HTML
    <div id="textBox1"></div>
    JavaScript
     $("#textBox1").dxTextBox({})
        .dxValidator({
            validationRules: []
        });
  • Knockout
    Apply the dxValidator binding to the div element that is bound to an editor.

    HTML
    <div data-bind="dxTextBox: { },
        dxValidator: { validationRules: [] }">  
    </div>
  • AngularJS
    Apply the dx-validator directive to the div element that represents an editor.

    HTML
    <div ng-controller="demoController">
        <div dx-text-box="{  }"
            dx-validator="{ validationRules:  }">  
        </div>
    </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 Installation article.

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

Configuration

An object defining configuration options for the dxValidator widget.

Name Description
adapter

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

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.

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.

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 dxValidator object.

validate()

Validates the value of the editor that is controlled by the current dxValidator 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

Fires when 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.