React Validator - NumericRule

A validation rule that demands that the validated field has a numeric value.

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

Object

ignoreEmptyValue

If set to true, empty values are valid.

Type:

Boolean

Default Value: true

message

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

Type:

String

Default Value: 'Value should be a number'

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, NumericRule } from 'devextreme-react/validator';
    •  
    • function App() {
    • return (
    • <TextBox>
    • <Validator>
    • <NumericRule
    • message="My custom message"
    • />
    • </Validator>
    • </TextBox>
    • );
    • }
  • Hide the message:

    App.tsx
    • import { TextBox } from 'devextreme-react/text-box';
    • import { Validator, NumericRule } from 'devextreme-react/validator';
    •  
    • function App() {
    • return (
    • <TextBox>
    • <Validator>
    • <NumericRule
    • message=""
    • />
    • </Validator>
    • </TextBox>
    • );
    • }
  • Display the editor's name in the default message (for instance, "Age should be a number"):

    App.tsx
    • import { TextBox } from 'devextreme-react/text-box';
    • import { Validator, NumericRule } from 'devextreme-react/validator';
    •  
    • function App() {
    • return (
    • <TextBox>
    • <Validator name="Age">
    • <NumericRule />
    • </Validator>
    • </TextBox>
    • );
    • }

type

Specifies the rule type. Set it to "numeric" to use the NumericRule.