-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidation.js
43 lines (38 loc) · 977 Bytes
/
validation.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
const Joi = require('joi');
const registerValidation = (data) => {
const schema = Joi.object({
name: Joi.string().alphanum().min(6).max(255).required(),
email: Joi.string()
.min(6)
.max(255)
.required()
.email({
minDomainSegments: 2,
tlds: { allow: ['com', 'net', 'fr'] },
}),
password: Joi.string()
.min(6)
.max(1024)
.pattern(new RegExp('^[a-zA-Z0-9]{3,30}$')),
});
return schema.validate(data);
};
const loginValidation = (data) => {
const schema = Joi.object({
email: Joi.string()
.min(6)
.max(255)
.required()
.email({
minDomainSegments: 2,
tlds: { allow: ['com', 'net'] },
}),
password: Joi.string()
.min(6)
.max(1024)
.pattern(new RegExp('^[a-zA-Z0-9]{3,30}$')),
});
return schema.validate(data);
};
module.exports.registerValidation = registerValidation;
module.exports.loginValidation = loginValidation;