forked from MashaDordevic/Makao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validations.js
47 lines (39 loc) · 1.42 KB
/
validations.js
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
import validator from 'validator';
let exp = {};
exp.validateLoginForm = (data) => {
var error = '';
var isValid = true;
if (!data || typeof data.email !== 'string' || data.email.trim().length === 0) {
isValid = false;
error = 'Email is required.';
} else if (!data || typeof data.password !== 'string' || data.password.trim().length === 0) {
isValid = false;
error = 'Password is required.';
}
return {
success: isValid,
error: error
}
}
exp.validateSignupForm = (data) => {
var error = '';
let isValid = true;
if (!data || typeof data.username !== 'string' || data.username.trim().length < 3) {
isValid = false;
error = 'Username with at least 3 alphanumeric characters is required.';
} else if (!data || typeof data.email !== 'string' || !validator.isEmail(data.email)) {
isValid = false;
error = 'Valid email address is required.';
} else if (!data || typeof data.password !== 'string' || data.password.trim().length < 8) {
isValid = false;
error = 'Password with at least 8 characters is required.';
} else if (!data || typeof data.confirmPassword !== 'string' || data.confirmPassword.trim() !== data.password.trim()) {
isValid = false;
error = 'Inserted passwords do not match.';
}
return {
success: isValid,
error: error
};
}
module.exports = exp;