Develop ultra fast with Prismane 🎉

email

This validator checks if a string is a valid email.

Basic Usage

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

console.log(email("martinpetrov404@gmail.com")); // Will return null
console.log(email("Ivan is cool"));
// Will return `This is not a valid email!`

useForm Hook Usage

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

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

API

Parameters

NameTypeDescription
valuestringThe string that will be validated.
regExpRegExp / undefinedAn optional parameter that will overwrite the regex that is used to match the email.