Angular Validator - StringLengthRule
A validation rule that demands the target value length be within the specified value range (including the range's end points).
import { StringLengthRule } from "devextreme/common"
Type:
message
Type:
Default Value: 'The length of the value is not correct'
An error message can be specified as follows:
Hard-code the message
app.component.htmlapp.module.ts- <dx-text-box>
- <dx-validator>
- <dxi-validation-rule
- type="stringLength"
- message="My custom message">
- </dxi-validation-rule>
- </dx-validator>
- </dx-text-box>
- import { BrowserModule } from '@angular/platform-browser';
- import { NgModule } from '@angular/core';
- import { AppComponent } from './app.component';
- import { DxValidatorModule,
- DxTextBoxModule } from 'devextreme-angular';
- @NgModule({
- declarations: [
- AppComponent
- ],
- imports: [
- DxTextBoxModule,
- BrowserModule,
- DxValidatorModule
- ],
- providers: [],
- bootstrap: [AppComponent]
- })
- export class AppModule { }
Hide the message
app.component.htmlapp.module.ts- <dx-text-box>
- <dx-validator>
- <dxi-validation-rule
- type="stringLength"
- message="">
- </dxi-validation-rule>
- </dx-validator>
- </dx-text-box>
- import { BrowserModule } from '@angular/platform-browser';
- import { NgModule } from '@angular/core';
- import { AppComponent } from './app.component';
- import { DxValidatorModule,
- DxTextBoxModule } from 'devextreme-angular';
- @NgModule({
- declarations: [
- AppComponent
- ],
- imports: [
- BrowserModule,
- DxValidatorModule,
- DxTextBoxModule
- ],
- providers: [],
- bootstrap: [AppComponent]
- })
- export class AppModule { }
Display the editor's name in the message
app.component.htmlapp.module.ts- <dx-text-box>
- <!-- The error message will be "The length of the password is not correct" -->
- <dx-validator name="password">
- <dxi-validation-rule
- type="stringLength">
- </dxi-validation-rule>
- </dx-validator>
- </dx-text-box>
- import { BrowserModule } from '@angular/platform-browser';
- import { NgModule } from '@angular/core';
- import { AppComponent } from './app.component';
- import { DxValidatorModule,
- DxTextBoxModule } from 'devextreme-angular';
- @NgModule({
- declarations: [
- AppComponent
- ],
- imports: [
- BrowserModule,
- DxValidatorModule,
- DxTextBoxModule
- ],
- providers: [],
- bootstrap: [AppComponent]
- })
- export class AppModule { }
Feel free to share topic-related thoughts here.
If you have technical questions, please create a support ticket in the DevExpress Support Center.
Thank you for the feedback!
If you have technical questions, please create a support ticket in the DevExpress Support Center.