Develop ultra fast with Prismane 🎉

ends

This validator checks if a string ends with a given substring.

Basic Usage

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

console.log(ends(".com", "mysite.com")); // Will return null
console.log(ends(".com", "mysite.eu")); // Will return an error`

useForm Hook Usage

function Demo() {
  const { handleSubmit, handleReset, register } = useForm({
    fields: {
      url: {
        value: "",
        validators: {
          ends: (v: string) => ends(v, ".com"),
        },
      },
    },
  });

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

API

Parameters

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