blob: d3b66e1e3688b774b0de7bbfd22d1dcc6af23b22 (
plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
function checkUsername() {
var username = document.getElementById("username").value;
var requirements = document.getElementById("username-requirements");
var len3 = username.length >= 3;
var nosymbol = username.match(/["'<>/&:;\\|{}[\]()]/) == null;
var nospace = username.match(/[ ]/) == null;
requirements.classList[len3 ? "add" : "remove"]("len-3");
requirements.classList[nosymbol ? "add" : "remove"]("nosymbol");
requirements.classList[nospace ? "add" : "remove"]("nospace");
requirements.parentElement.classList.remove("all");
if (!len3) return false;
if (!nosymbol) return false;
if (!nospace) return false;
requirements.parentElement.classList.add("all");
return true;
}
function checkEmail() {
var email = document.getElementById("email").value;
var requirements = document.getElementById("email-requirements");
// e-mail addresses can really only be verified by attempting to send a mail
// to them, so this is pretty much useless for client-side anyways
var valid = email.match(/.+?@.+/) != null;
requirements.classList[valid ? "add" : "remove"]("valid");
requirements.parentElement.classList.remove("all");
if (!valid) return false;
requirements.parentElement.classList.add("all");
return true;
}
function checkPassword() {
var password = document.getElementById("password").value;
var requirements = document.getElementById("password-requirements");
var len8 = password.length >= 8;
var minnum2 = password.match(/[0-9]/g)?.length >= 2;
var minsym2 = password.match(/[!@#$%^&*()\-=_+[\]{}\\|;:'",<.>/?`~]/g)?.length >= 2;
var uppercase = password.match(/[A-Z]/) != null;
var lowercase = password.match(/[a-z]/) != null;
requirements.classList[len8 ? "add" : "remove"]("len-8");
requirements.classList[minnum2 ? "add" : "remove"]("digit-2");
requirements.classList[minsym2 ? "add" : "remove"]("symbol-2");
requirements.classList[uppercase ? "add" : "remove"]("has-uppercase");
requirements.classList[lowercase ? "add" : "remove"]("has-lowercase");
requirements.parentElement.classList.remove("all");
if (!len8) return false;
if (!minnum2) return false;
if (!minsym2) return false;
if (!uppercase) return false;
if (!lowercase) return false;
requirements.parentElement.classList.add("all");
return true;
}
function checkAllFields() {
var username = checkUsername();
var email = checkEmail();
var password = checkPassword();
if (!username) return false;
if (!email) return false;
if (!password) return false;
return true;
}
function updateRegisterButton() {
document.getElementById("register-submit").disabled = !checkAllFields();
}
// update when fields are changed
document.getElementById("username").addEventListener("input", updateRegisterButton);
document.getElementById("email").addEventListener("input", updateRegisterButton);
document.getElementById("password").addEventListener("input", updateRegisterButton);
updateRegisterButton();
|