React Validator - RangeRule
A validation rule that demands the target value be within the specified value range (including the range's end points).
import { RangeRule } from "devextreme/common"
Type:
To specify the range that the validated value must match, set the rule's min and max configuration properties. Note that the specified range can be on a date-time or numeric scale. To validate a value against a string length, use the stringLength rule.
See Also
message
Specifies the message that is shown if the rule is broken.
Type:
Default Value: 'Value is out of range'
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, RangeRule } from 'devextreme-react/validator';
- function App() {
- return (
- <TextBox>
- <Validator>
- <RangeRule
- message="My custom message"
- />
- </Validator>
- </TextBox>
- );
- }
Hide the message:
App.tsx- import { TextBox } from 'devextreme-react/text-box';
- import { Validator, RangeRule } from 'devextreme-react/validator';
- function App() {
- return (
- <TextBox>
- <Validator>
- <RangeRule
- message=""
- />
- </Validator>
- </TextBox>
- );
- }
Display the editor's name in the default message (for instance, "Age is out of range"):
App.tsx- import { TextBox } from 'devextreme-react/text-box';
- import { Validator, RangeRule } from 'devextreme-react/validator';
- function App() {
- return (
- <TextBox>
- <Validator name="Age">
- <RangeRule />
- </Validator>
- </TextBox>
- );
- }