Develop ultra fast with Prismane 🎉

contains

This validator checks if a string contains a given substring.

Basic Usage

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

console.log(contains("https://", "https://www.mysite.com")); // Will return null
console.log(contains("https://", "mysite.com")); // Will return an error`

useForm Hook Usage

function Demo() {
  const { handleSubmit, handleReset, register } = useForm({
    fields: {
      url: {
        value: "",
        validators: {
          contains: (v: string) => contains(v, "https://"),
        },
      },
    },
  });

  return (
    <Form
      onSubmit={(e: any) => {
        handleSubmit(e, (v: any) => console.log(v));
      }}
      onReset={() => handleReset()}
      maw={300}
    >
      <TextField
        placeholder="eg. https://www.mysite.com"
        label="URL:"
        {...register("url")}
      />
      <Button type="submit">Submit</Button>
    </Form>
  );
}

API

Parameters

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