-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathSignUpFormValidationRules.js
More file actions
43 lines (36 loc) · 1004 Bytes
/
SignUpFormValidationRules.js
File metadata and controls
43 lines (36 loc) · 1004 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
*
* This file is to be used to perform all form validation.
* It is keep apart on a different file for organization.
* As validate is a JavaScript function, you can perform any kind of data manipulation/validation.
* Return a object with errors by field.
*/
/**
*
* @param {*} { firstName, lastName, email, subject, password }
* @returns errors: {}
*/
const validate = ({
firstName, lastName, email, subject, password,
}) => {
const errors = {};
if (!firstName.value) {
errors.firstName = 'First name is required';
}
if (!lastName.value) {
errors.lastName = 'Last name is required';
}
if (!email.value) {
errors.email = 'Email address is required';
} else if (!/\S+@\S+\.\S+/.test(email.value)) {
errors.email = 'Email address is invalid';
}
if (!subject.value) {
errors.subject = 'A subject of interest is required.';
}
if (!password.value) {
errors.password = 'Password is required';
}
return errors;
};
export default validate;