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