form-validators

0.0.16 • Public • Published

CircleCI

form-validators

A collection of javascript form validators

isEmail

import { isEmail } from "form-validators";

// Create the email validator
const emailValidator = isEmail();
emailValidator("email@domain.com"); // undefined
emailValidator("not an email address"); // 'not an email address' is not a valid email address.

// Define a custom error message
const customEmailValidator = isEmail("You dun goofed!");
customEmailValidator("email@domain.com"); // undefined
customEmailValidator("not an email address"); // You dun goofed!

// Optionaly pass a function that recieves the email adress to build a custom error message
const dynamicCustomEmailValidator = isEmail(
  ({ value }) => `Hmm... I don't think '${value}' is a valid email address.`
);
dynamicCustomEmailValidator("email@domain.com"); // undefined
dynamicCustomEmailValidator("not an email address"); // Hmm... I don't think 'not an email address' is a valid email address.

Readme

Keywords

none

Package Sidebar

Install

npm i form-validators

Weekly Downloads

1

Version

0.0.16

License

ISC

Unpacked Size

7.79 kB

Total Files

12

Last publish

Collaborators

  • luk707