-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidation.js
More file actions
51 lines (48 loc) · 1.26 KB
/
validation.js
File metadata and controls
51 lines (48 loc) · 1.26 KB
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
44
45
46
47
48
49
50
51
const loginValidation = (data, res) => {
const { email, password } = data;
if (!email) {
res.status(400).send('Email cannot be empty!');
return false;
}
if (!email.includes('@')) {
res.status(400).send('Invalid email!');
return false;
}
if (!password) {
res.status(400).send('Password cannot be empty!');
return false;
}
if (password.length < 6) {
res.status(400).send('Password length cannot be less than 6 characters');
}
return true;
};
const registerValidation = (data, res) => {
const { email, password, confirmPassword, lastName, firstName } = data;
if (!email) {
res.status(400).send('Email is required');
return false;
}
if (!firstName) {
res.status(400).send('First name is required');
return false;
}
if (!lastName) {
res.status(400).send('Last name is required');
return false;
}
if (!email.includes('@')) {
res.status(400).send('Invalid email');
return false;
}
if (password != confirmPassword) {
res.status(400).send('The two password must match!');
return false;
}
if (password.length < 6) {
res.status(400).send('Input at least 6 character length for password');
return false;
}
return true;
};
module.exports = { loginValidation, registerValidation };