Develop ultra fast with Prismane 🎉

negative

This validator checks if a number is negative.

Basic Usage

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

console.log(negative(-1)); // Will return null
console.log(negative(1)); // Will return an error`

useForm Hook Usage

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

  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.
fieldNamestring / undefinedThe name of the field.