-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathvalidation.js
More file actions
49 lines (39 loc) · 1.49 KB
/
validation.js
File metadata and controls
49 lines (39 loc) · 1.49 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
// import module `check` from `express-validator`
const { check } = require('express-validator');
/*
defines an object which contains functions
which returns array of validation middlewares
*/
const validation = {
/*
function which returns an array of validation middlewares
called when the client sends an HTTP POST request for `/signup`
*/
signupValidation: function () {
/*
object `validation` is an array of validation middlewares.
the first parameter in method check() is the field to check
the second parameter in method check() is the error message
to be displayed when the value to the parameter fails
the validation
*/
var validation = [
// checks if `fName` is not empty
check('fName', 'First name should not be empty.').notEmpty(),
// checks if lName is not empty
check('lName', 'Last name should not be empty.').notEmpty(),
// checks if `idNum` contains exactly 8 digits
check('idNum', 'ID number should contain 8 digits.')
.isLength({min: 8, max: 8}),
// checks if `pw` contains at least 8 characters
check('pw', 'Passwords should contain at least 8 characters.')
.isLength({min: 8})
];
return validation;
}
}
/*
exports the object `validation` (defined above)
when another script exports from this file
*/
module.exports = validation;