Skip to content

Instantly share code, notes, and snippets.

@wwwhatley
Last active July 14, 2018 20:32
Show Gist options
  • Save wwwhatley/7d04836d1b0cd754854502e9ae1c132f to your computer and use it in GitHub Desktop.
Save wwwhatley/7d04836d1b0cd754854502e9ae1c132f to your computer and use it in GitHub Desktop.
validate={values => {
let errors = {};
// REGEX
let regex = !/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
// VALIDATION
if (!values.email) {
errors.email = "Email is required";
} else if (regex.test(values.email)) {
errors.email = "Invalid email address";
}
if (!values.password) {
errors.password = "A password is required";
} else if (values.password.length < 6) {
errors.password = "Password must be 6 characters";
}
return errors;
}}
onSubmit={values => {
console.log(values);
}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment