-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
82 lines (82 loc) · 2.79 KB
/
main.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
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
document.title = "project-js-5";
let input_1 = document.querySelector(".name-1");
let input_2 = document.querySelector(".name-2");
let input_3 = document.querySelector(".name-3");
let input_4 = document.querySelector(".name-4");
window.onload = function () {
if (input_1.value === "") {
input_1.value = window.sessionStorage.getItem("input_1");
};
if (input_2.value === "") {
input_2.value = window.sessionStorage.getItem("input_2");
};
if (input_3.value === "") {
input_3.value = window.sessionStorage.getItem("input_3");
};
if (input_4.value === "") {
input_4.value = window.sessionStorage.getItem("input_4");
};
input_1.focus();
};
input_1.addEventListener("blur",function () {
input_2.focus();
});
input_2.addEventListener("blur",function () {
input_3.focus();
});
input_3.addEventListener("blur",function () {
input_4.focus();
});
input_1.onmouseleave = function () {
window.sessionStorage.setItem("input_1", this.value);
};
input_2.onmouseleave = function () {
window.sessionStorage.setItem("input_2", this.value);
};
input_3.onmouseleave = function () {
window.sessionStorage.setItem("input_3", this.value);
};
input_4.onmouseleave = function () {
window.sessionStorage.setItem("input_4", this.value);
};
input_1.addEventListener("blur", function () {
window.sessionStorage.setItem("input_1", this.value);
});
input_2.addEventListener("blur", function () {
window.sessionStorage.setItem("input_2", this.value);
});
input_3.addEventListener("blur", function () {
window.sessionStorage.setItem("input_3", this.value);
});
input_4.addEventListener("blur", function () {
window.sessionStorage.setItem("input_4", this.value);
});
let nameInput = document.getElementById("name");
let passwordInput = document.getElementById("password");
let mailInput = document.getElementById("mail");
document.forms[0].addEventListener("submit", function (event) {
let nameValid = false;
let passwordValid = false;
let mailValid = false;
if (nameInput.value !== "" && 7 <= nameInput.value.length) {
nameValid = true;
}
if (passwordInput.value !== "" && 11 <= passwordInput.value.length) {
passwordValid = true;
}
if (mailInput.value !== "") {
mailValid = true;
}
if (nameValid === false || passwordValid === false || mailValid === false) {
event.preventDefault();
}
});
document.getElementById("register").onsubmit = function () {
let phoneInput = document.getElementById("phone").value;
let phoneRe = /\(\d{4}\)\s\d{3}-\d{4}/; // (1234) 567-8910
let validationResult_1 = phoneRe.test(phoneInput);
if (validationResult_1 === false) {
return false;
}
return true;
};