Develop ultra fast with Prismane 🎉

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

NameTypeDescription
valuestring / number / booleanThe value that will be matched.
booleanstring / number / booleanThe second value that will be matched.
fieldNamestring / undefinedThe name of the field.