2016-11-16 18:12:36 +00:00
|
|
|
/* eslint-disable */
|
|
|
|
export const domOnlyProps = ({
|
|
|
|
initialValue,
|
|
|
|
autofill,
|
|
|
|
onUpdate,
|
|
|
|
valid,
|
|
|
|
invalid,
|
|
|
|
dirty,
|
|
|
|
pristine,
|
|
|
|
active,
|
|
|
|
touched,
|
|
|
|
visited,
|
|
|
|
autofilled,
|
|
|
|
error,
|
|
|
|
...domProps }) => domProps;
|
|
|
|
/* eslint-enable */
|
2017-03-16 22:25:12 +00:00
|
|
|
|
2019-07-23 18:16:05 +00:00
|
|
|
// eslint-disable-next-line max-len
|
|
|
|
const EMAIL_REGEX = /^(([^<>()[\]\\.,;:\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,}))$/i;
|
|
|
|
|
2017-03-16 22:25:12 +00:00
|
|
|
function validateNameEmail(formProps, errors) {
|
|
|
|
if (!formProps.username) {
|
|
|
|
errors.username = 'Please enter a username.';
|
|
|
|
} else if (!formProps.username.match(/^.{1,20}$/)) {
|
|
|
|
errors.username = 'Username must be less than 20 characters.';
|
|
|
|
} else if (!formProps.username.match(/^[a-zA-Z0-9._-]{1,20}$/)) {
|
|
|
|
errors.username = 'Username must only consist of numbers, letters, periods, dashes, and underscores.';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!formProps.email) {
|
|
|
|
errors.email = 'Please enter an email.';
|
2017-06-06 02:33:32 +00:00
|
|
|
} else if (
|
|
|
|
// eslint-disable-next-line max-len
|
2019-07-23 18:16:05 +00:00
|
|
|
!formProps.email.match(EMAIL_REGEX)) {
|
2017-03-16 22:25:12 +00:00
|
|
|
errors.email = 'Please enter a valid email address.';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function validateSettings(formProps) {
|
|
|
|
const errors = {};
|
|
|
|
|
|
|
|
validateNameEmail(formProps, errors);
|
|
|
|
|
|
|
|
if (formProps.currentPassword && !formProps.newPassword) {
|
|
|
|
errors.newPassword = 'Please enter a new password or leave the current password empty.';
|
|
|
|
}
|
2019-10-17 16:53:11 +00:00
|
|
|
if (formProps.newPassword && formProps.newPassword.length < 6) {
|
|
|
|
errors.newPassword = 'Password must be at least 6 characters';
|
|
|
|
}
|
2017-03-16 22:25:12 +00:00
|
|
|
return errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function validateLogin(formProps) {
|
|
|
|
const errors = {};
|
|
|
|
if (!formProps.email) {
|
|
|
|
errors.email = 'Please enter an email';
|
|
|
|
}
|
|
|
|
if (!formProps.password) {
|
|
|
|
errors.password = 'Please enter a password';
|
|
|
|
}
|
|
|
|
return errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function validateSignup(formProps) {
|
|
|
|
const errors = {};
|
|
|
|
|
|
|
|
validateNameEmail(formProps, errors);
|
|
|
|
|
|
|
|
if (!formProps.password) {
|
|
|
|
errors.password = 'Please enter a password';
|
|
|
|
}
|
2019-10-17 16:53:11 +00:00
|
|
|
if (formProps.password && formProps.password.length < 6) {
|
|
|
|
errors.password = 'Password must be at least 6 characters';
|
2019-03-15 21:35:48 +00:00
|
|
|
}
|
2017-03-16 22:25:12 +00:00
|
|
|
if (!formProps.confirmPassword) {
|
|
|
|
errors.confirmPassword = 'Please enter a password confirmation';
|
|
|
|
}
|
|
|
|
|
2019-03-20 21:53:03 +00:00
|
|
|
if (formProps.password !== formProps.confirmPassword && formProps.confirmPassword) {
|
|
|
|
errors.confirmPassword = 'Passwords must match';
|
2017-03-16 22:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return errors;
|
|
|
|
}
|
2019-07-23 18:16:05 +00:00
|
|
|
export function validateResetPassword(formProps) {
|
|
|
|
const errors = {};
|
|
|
|
if (!formProps.email) {
|
|
|
|
errors.email = 'Please enter an email.';
|
|
|
|
} else if (
|
|
|
|
// eslint-disable-next-line max-len
|
|
|
|
!formProps.email.match(EMAIL_REGEX)) {
|
|
|
|
errors.email = 'Please enter a valid email address.';
|
|
|
|
}
|
|
|
|
return errors;
|
|
|
|
}
|