Develop ultra fast with Prismane 🎉

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

NameTypeDescription
valuenumberThe number that will be validated.
ofnumberThe number that will be checked.
fieldNamestring / undefinedThe name of the field.