Skip to content

Instantly share code, notes, and snippets.

@suzdalnitski
Created August 13, 2018 00:18
Show Gist options
  • Save suzdalnitski/00978d89233cbc4780d9d28c55732a31 to your computer and use it in GitHub Desktop.
Save suzdalnitski/00978d89233cbc4780d9d28c55732a31 to your computer and use it in GitHub Desktop.
import { withProps } from "recompose";
const getPasswordError = password => {
if (!password.isDirty) {
return "";
}
const passwordRegex = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$/;
const isValidPassword = passwordRegex.test(password.value);
return !isValidPassword
? "The password must contain minimum eight characters, at least one letter and one number."
: "";
};
const withPasswordError = withProps(ownerProps => ({
passwordError: getPasswordError(ownerProps.password)
}));
export default withPasswordError;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment