javascript

Enter only number field validation redux form

You can apply the number-only input field validation by creating a function that can check if the given value is a number or not.

const numberValidator = value => value && isNaN(Number(value)) ? 'Must be a number' : undefined

<Field 
    name="totalScore" 
    type="number"
    component={renderField}
    label="Total Score"
    validate={[ numberValidator ]}
/>
Was this helpful?