Skip to content

Instantly share code, notes, and snippets.

@suzdalnitski
Created August 13, 2018 00:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suzdalnitski/6880f54f64400acc2a24aba00b009a0c to your computer and use it in GitHub Desktop.
Save suzdalnitski/6880f54f64400acc2a24aba00b009a0c to your computer and use it in GitHub Desktop.
import { withProps } from "recompose";
const getEmailError = email => {
if (!email.isDirty) {
return "";
}
const emailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
const isValidEmail = emailRegex.test(email.value);
return !isValidEmail ? "Invalid email." : "";
};
const withEmailError = withProps(ownerProps => ({
emailError: getEmailError(ownerProps.email)
}));
export default withEmailError;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment