-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.js
More file actions
26 lines (26 loc) · 867 Bytes
/
functions.js
File metadata and controls
26 lines (26 loc) · 867 Bytes
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
module.exports = {
generateRandomString : function() {
const set = '0123456789abcdefghijklmnopqrstuvwxyz'.split('');
const output = [];
for (let i = 0; i < 6; i++) {
output.push(set[Math.floor(Math.random() * 36)]);
}
return output.join('');
},
// Backend verification of email adrress
validateEmail: function (email) {
const re = /^(([^<>()\[\]\\.,;:\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,}))$/;
return re.test(String(email).toLowerCase());
},
validateUser: function (userset, name, email) {
for (let data in userset) {
if (userset[data].userName === name || userset[data].userEmail === email) {
return true;
}
}
return false;
},
generateId: function () {
return Math.random().toString(36).replace(/[^a-z]+/g, '').substr(2, 10);
}
};