Develop ultra fast with Prismane 🎉

less

This validator checks if a number is less than a given number.

Basic Usage

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

console.log(less(10, 20)); // Will return null
console.log(less(40, 20)); // Will return an error`

useForm Hook Usage

function Demo() {
  const { handleSubmit, handleReset, register } = useForm({
    fields: {
      age: {
        value: 9,
        validators: {
          less: (v: any) => less(v, 10),
        },
      },
    },
  });

  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.
numbernumberThe number that will be compared.
fieldNamestring / undefinedThe name of the field.