2016-11-16 19:12:36 +01: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 23:25:12 +01: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 04:33:32 +02:00
|
|
|
} else if (
|
|
|
|
// eslint-disable-next-line max-len
|
|
|
|
!formProps.email.match(/^(([^<>()[\]\\.,;:\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 23:25:12 +01: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.';
|
|
|
|
}
|
|
|
|
|
|
|
|
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-03-15 22:35:48 +01:00
|
|
|
if (formProps.password) {
|
|
|
|
if (formProps.password.length < 6) {
|
|
|
|
errors.password = 'Password must be at least 6 characters';
|
|
|
|
}
|
|
|
|
}
|
2017-03-16 23:25:12 +01:00
|
|
|
if (!formProps.confirmPassword) {
|
|
|
|
errors.confirmPassword = 'Please enter a password confirmation';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (formProps.password !== formProps.confirmPassword) {
|
|
|
|
errors.password = 'Passwords must match';
|
|
|
|
}
|
|
|
|
|
|
|
|
return errors;
|
|
|
|
}
|