JavaScript/jQuery Validator - RequiredRule

A validation rule that rejects empty and invalid values.

import { RequiredRule } from "devextreme/common"
Type:

Object

The following values break RequiredRule:

View Demo

See Also

message

Specifies the message that is shown if the rule is broken.

Type:

String

Default Value: 'Required'

An error message can be specified as follows:

  • Hard-code the message

    index.js
    • $(function() {
    • $("#textBox").dxTextBox({ ... })
    • .dxValidator({
    • type: "required",
    • message: "My custom message"
    • });
    • });
  • Hide the message

    index.js
    • $(function() {
    • $("#textBox").dxTextBox({ ... })
    • .dxValidator({
    • type: "required",
    • message: ""
    • });
    • });
  • Display the editor's name in the message

    index.js
    • $(function() {
    • $("#textBox").dxTextBox({ ... })
    • .dxValidator({
    • name: "Password", // The error message will be "Password is required"
    • validationRules: [{
    • type: "required"
    • }]
    • });
    • });

trim

Indicates whether to remove the Space characters from the validated value.

Type:

Boolean

Default Value: true

To keep the Space characters within the validated value, set this field to false.

type

Specifies the rule type. Set it to "required" to use the RequiredRule.