match
This validator checks if a given set of variables are the same.Basic Usage
import { match } from "@prismane/core/validators"; console.log(match("password", "password")); // Will return null console.log(match("password", "password1234")); // Will return `Fields must match!` console.log(match("password", "password1234", "Passwords")); // Will return `Passwords must match!`
useForm Hook Usage
function Demo() { const { handleSubmit, handleReset, register, getValue } = useForm({ fields: { password: { value: "", validators: { match: (v: string) => match(v, "password"), }, }, repassword: { value: "password", }, }, }); return ( <Form onSubmit={(e: any) => { handleSubmit(e, (v: any) => console.log(v)); }} onReset={() => handleReset()} maw={300} > <TextField placeholder="Enter password: " label="Password:" {...register("password")} /> <TextField placeholder="Retype password: " label="Retype Password:" readOnly {...register("repassword")} /> <Button type="submit">Submit</Button> </Form> ); }
API
Parameters
Name | Type | Description |
---|---|---|
value | string / number / boolean | The value that will be matched. |
boolean | string / number / boolean | The second value that will be matched. |
fieldName | string / undefined | The name of the field. |