Develop ultra fast with Prismane 🎉

trimmed

This validator checks if a string has no more than one consecutive spaces.

Basic Usage

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

console.log(trimmed("John Doe")); // Will return null
console.log(trimmed("John                           Doe")); // Will return an error`

useForm Hook Usage

function Demo() {
  const { handleSubmit, handleReset, register } = useForm({
    fields: {
      name: {
        value: "",
        validators: {
          trimmed: (v: string) => trimmed(v),
        },
      },
    },
  });

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

API

Parameters

NameTypeDescription
valuestringThe string that will be validated.
regExpRegExp / undefinedAn optional parameter that will overwrite the default regex used to match the string.
fieldNamestring / undefinedThe name of the field.