Develop ultra fast with Prismane 🎉

between

This validator checks if a number is between an interval of two numbers.

Basic Usage

import { between } from "@prismane/core/validators";

console.log(between(10, 0, 30)); // Will return null
console.log(between(40, 0, 30)); // Will return an error`

useForm Hook Usage

function Demo() {
  const { handleSubmit, handleReset, register } = useForm({
    fields: {
      age: {
        value: 0,
        validators: {
          between: (v: any) => between(v, 0, 120),
        },
      },
    },
  });

  return (
    <Form
      onSubmit={(e: any) => {
        handleSubmit(e, (v: any) => console.log(v));
      }}
      onReset={() => handleReset()}
      maw={300}
    >
      <NumberField
        placeholder="Enter age: "
        label="Age:"
        {...register("age")}
      />
      <Button type="submit">Submit</Button>
    </Form>
  );
}

API

Parameters

NameTypeDescription
valuenumberThe number that will be validated.
minnumberThe minimum of the range.
maxnumberThe maximum of the range.
fieldNamestring / undefinedThe name of the field.