less
This validator checks if a number is less than a given number.Basic Usage
import { less } from "@prismane/core/validators"; console.log(less(10, 20)); // Will return null console.log(less(40, 20)); // Will return an error`
useForm Hook Usage
function Demo() { const { handleSubmit, handleReset, register } = useForm({ fields: { age: { value: 9, validators: { less: (v: any) => less(v, 10), }, }, }, }); 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. |
number | number | The number that will be compared. |
fieldName | string / undefined | The name of the field. |