Develop ultra fast with Prismane 🎉

uuid

This validator checks if a string is a valid ID.

Basic Usage

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

console.log(uuid("1a2b3c4d5e6f7890")); // Will return null
console.log(uuid("invaliduuid123")); // Will return an error`

useForm Hook Usage

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

  return (
    <Form
      onSubmit={(e: any) => {
        handleSubmit(e, (v: any) => console.log(v));
      }}
      onReset={() => handleReset()}
      maw={300}
    >
      <TextField
        placeholder="eg. 1a2b3c4d5e6f7890"
        label="ID:"
        {...register("id")}
      />
      <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.