-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate.js
38 lines (38 loc) · 1.1 KB
/
validate.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
// Regex for alphanumeric: ^[a-zA-Z0-9]{1}$
var profanityfinder = require('profanity-finder');
var findProfanity = profanityfinder.findprofanity;
const isAZaz09=require("./isAlphanumeric.js");
const validate=function(username) {
if(!username instanceof String) {
return false;
}
// AbortController can't be tampered with. Activated if any character is invalid.
if(username.length>20 || username.length<3) {
return false;
}
if(findProfanity(username)) {
return false;
}
const isValid=new AbortController();
const usernameArray=Array.from(username);
usernameArray.forEach(function(char) {
if(isValid.signal.aborted) return false;
const charIsValid=new AbortController();
if(isAZaz09(char)) charIsValid.abort();
if(char=="_") charIsValid.abort();
if(char=="-") charIsValid.abort();
if(!charIsValid.signal.aborted) {
// console.log(1);
isValid.abort();
}
});
// console.log(isValid.aborted);
if(isValid.signal.aborted) {
return false;
}
else {
return true;
}
// var matches=username.match(^[a-z0-9_-].*?$)
}
module.exports=validate;