between
This validator checks if a number is between an interval of two numbers.Basic Usage
import { between } from "@prismane/core/validators"; console.log(between(10, 0, 30)); // Will return null console.log(between(40, 0, 30)); // Will return an error`
useForm Hook Usage
function Demo() { const { handleSubmit, handleReset, register } = useForm({ fields: { age: { value: 0, validators: { between: (v: any) => between(v, 0, 120), }, }, }, }); return ( <Form onSubmit={(e: any) => { handleSubmit(e, (v: any) => console.log(v)); }} onReset={() => handleReset()} maw={300} > <NumberField placeholder="Enter age: " label="Age:" {...register("age")} /> <Button type="submit">Submit</Button> </Form> ); }
API
Parameters
Name | Type | Description |
---|---|---|
value | number | The number that will be validated. |
min | number | The minimum of the range. |
max | number | The maximum of the range. |
fieldName | string / undefined | The name of the field. |