-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdataAccess.js
More file actions
61 lines (47 loc) · 1.39 KB
/
dataAccess.js
File metadata and controls
61 lines (47 loc) · 1.39 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
52
53
54
55
56
57
58
59
60
61
var spamService = require('./services/spamService');
var databaseConnection = require('./databaseConnection');
function dataAccess(){
}
dataAccess.prototype.saveRecord = function saveRecord(firstName, lastName, emailAddress) {
if(!new databaseConnection("(local)", 30, "Contacts").isConnected()){
return false;
}
if (firstName.length <= 10)
{
var firstNameRegex = /^[a-z]+$/i
if(!firstNameRegex.test(firstName)){
return false;
}
}
else{
return false;
}
if(lastName.includes('-')){
var lastNameParts = lastName.split('-');
for(i = 0; i< lastNameParts.length; i++){
var lastNameRegex = /^[a-z]+$/i;
if(!lastNameRegex.test(lastNameParts[i])){
return false;
}
}
}
else if (lastName.length <= 20)
{
var lastNameRegex = /^[a-z]+$/i;
if(!lastNameRegex.test(lastName)){
return false;
}
}
else{
return false;
}
var emailRegex = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if(!emailRegex.test(emailAddress)){
return false;
}
if(spamService.isKnownSpam(emailAddress)){
return false;
}
return true;
}
module.exports = dataAccess;