-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidation.js
More file actions
76 lines (69 loc) · 2.4 KB
/
validation.js
File metadata and controls
76 lines (69 loc) · 2.4 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
function signupValidation() {
var result = true;
// email
var email = document.getElementById('studentEmail').value;
var atIndex = email.indexOf('@');
var dotIndex = email.indexOf('.');
if (atIndex == 0 || dotIndex >= email.length-2 || dotIndex - atIndex < 3) {
var warning = document.getElementById('emailFormatWarning');
warning.style.display = 'block';
result = false;
}
// password
var password = document.getElementById('studentPassword').value;
let s = false;
let c = false;
let n = false;
let sc = false;
for (let i = 0; i < password.length; i++) {
const p = password[i];
if (p >= 'A' && p <= 'Z') {
c = true;
} else if (p >= 'a' && p <= 'b') {
s = true;
} else if (p >= '0' && p <= '9') {
n = true;
} else if (p >= '!' && p <= '~') {
sc = true;
} else {
break;
}
}
if (c == false || s == false || n == false || sc == false) {
let warning = document.getElementById('passwordFormatWarning');
warning.style.display = 'block';
result = false;
}
// confirm password
var confirmPassword = document.getElementById('studentCPassword').value;
var password = document.getElementById('studentPassword').value;
if (password != confirmPassword) {
var warning = document.getElementById('passwordUnmatchWarning');
warning.style.display = 'block';
result = false;
}
return result;
}
function checkEmail(str) {
var req = new XMLHttpRequest();
req.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("invalidEmail").innerHTML = this.responseText;
email = str;
}
}
req.open("post", "checkEmail.php?w=1", true);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.send("email=" + str);
}
function verifyPassword(str) {
var req = new XMLHttpRequest();
req.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
document.getElementById('wrongPassword').innerHTML = this.responseText;
}
}
req.open("post", "checkEmail.php?email=" + email, true);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.send("password=" + str);
}