Angular Validator - RequiredRule
A validation rule that rejects empty and invalid values.
import { RequiredRule } from "devextreme/common"
Type:
The following values break RequiredRule:
- Falsy JavaScript values except
0,-0,0n, andNaN. - Invalid values for the target editor (for example, a non-numeric string for the NumberBox component).
See Also
message
Specifies the message that is shown if the rule is broken.
Type:
Default Value: 'Required'
You can configure an error message in the following ways:
Specify a hard-coded message:
app.component.htmlapp.module.ts- <dx-text-box>
- <dx-validator>
- <dxi-validator-validation-rule
- type="required"
- message="My custom message">
- </dxi-validator-validation-rule>
- </dx-validator>
- </dx-text-box>
- import { DxValidatorModule, DxTextBoxModule } from 'devextreme-angular';
- // ...
- @NgModule({
- imports: [
- DxTextBoxModule,
- DxValidatorModule,
- ],
- })
Hide the message:
app.component.html- <dx-text-box>
- <dx-validator>
- <dxi-validator-validation-rule
- type="required"
- message="">
- </dxi-validator-validation-rule>
- </dx-validator>
- </dx-text-box>
Display the editor's name in the default message (for instance, "Password is required"):
app.component.html- <dx-text-box>
- <dx-validator name="Password">
- <dxi-validator-validation-rule
- type="required"
- ></dxi-validator-validation-rule>
- </dx-validator>
- </dx-text-box>
trim
Indicates whether to remove the Space characters from the validated value.
Type:
Default Value: true
To keep the Space characters within the validated value, set this field to false.