form-validators
v0.0.16
Published
A collection of javascript form validators Edit
Downloads
4
Readme
form-validators
A collection of javascript form validators
isEmail
import { isEmail } from "form-validators";
// Create the email validator
const emailValidator = isEmail();
emailValidator("[email protected]"); // 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 protected]"); // 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 protected]"); // undefined
dynamicCustomEmailValidator("not an email address"); // Hmm... I don't think 'not an email address' is a valid email address.