Develop ultra fast with Prismane 🎉

substring

This validator checks if a string is a substring of a given string.

Basic Usage

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

console.log(substring("martin", "martinpetrov")); // Will return null
console.log(substring("michael", "ivanpetkanov")); // Will return an error`

useForm Hook Usage

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

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

API

Parameters

NameTypeDescription
valuestringThe string that will be validated.
stringstringThe string that will be searched in.
fieldNamestring / undefinedThe name of the field.