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