React 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
Specifies the message that is shown if the rule is broken.
Type:
Default Value: 'The length of the value is not correct'
You can configure an error message in the following ways:
Specify a hard-coded message:
App.tsx- import { TextBox } from 'devextreme-react/text-box';
- import { Validator, StringLengthRule } from 'devextreme-react/validator';
- function App() {
- return (
- <TextBox>
- <Validator>
- <StringLengthRule
- message="My custom message"
- />
- </Validator>
- </TextBox>
- );
- }
Hide the message:
App.tsx- import { TextBox } from 'devextreme-react/text-box';
- import { Validator, StringLengthRule } from 'devextreme-react/validator';
- function App() {
- return (
- <TextBox>
- <Validator>
- <StringLengthRule
- message=""
- />
- </Validator>
- </TextBox>
- );
- }
Display the editor's name in the default message (for instance, "The length of the password is not correct"):
App.tsx- import { TextBox } from 'devextreme-react/text-box';
- import { Validator, StringLengthRule } from 'devextreme-react/validator';
- function App() {
- return (
- <TextBox>
- <Validator name="password">
- <StringLengthRule />
- </Validator>
- </TextBox>
- );
- }
trim
Indicates whether or not 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.