Develop ultra fast with Prismane 🎉

max

This validator checks if a given string's length is less than a given maximum.

Basic Usage

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

console.log(max("Ivan is very cool", 100, "Username")); // Will return null
console.log(max("Ivan is very cool", 2, "Username"));
// Will return `Username has to be shorter than 100 characters!`

useForm Hook Usage

function Demo() {
  const { handleSubmit, handleReset, register } = useForm({
    fields: {
      username: {
        value: "",
        validators: {
          max: (v: string) => max(v, 4, "Username"),
        },
      },
    },
  });

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

API

Parameters

NameTypeDescription
valuestringThe string that will be validated.
lengthnumberThe maximum length of the string.
fieldNamestring / undefinedThe name of the field.