Skip to content

Instantly share code, notes, and snippets.

@tofazzal-shuvo
Created December 26, 2019 11:55
Show Gist options
  • Select an option

  • Save tofazzal-shuvo/9d8b596e87cbd4eed3718abc6816e38f to your computer and use it in GitHub Desktop.

Select an option

Save tofazzal-shuvo/9d8b596e87cbd4eed3718abc6816e38f to your computer and use it in GitHub Desktop.
import validator from "validator";
export default (name, value, required) => {
if (!value && required) {
if (name === "email") return { [name]: "Email can't be empty!" };
else if (name === "password") return { [name]: "Password can't be empty!" };
} else {
if (name === "password" && value.length < 6)
return { [name]: "Password can't be less then 6 character!" };
else if (name === "email" && !validator.isEmail(value))
return { [name]: "Email is badly formatted!" };
return { [name]: "" };
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment