-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
90 lines (79 loc) · 3.12 KB
/
script.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
83
84
85
86
87
88
89
90
// function changeImage() {
// if (document.getElementById("heartVoid").src == "/images/HeartVoid.png"){
// document.getElementById("heartVoid").src = "/images/HeartFill.png";
// } else {
// document.getElementById("heartVoid").src = "/images/HeartVoid.png";
// }
// }
// const heart = document.getElementById("heartVoid");
// function changeImage(element) {
// element.classList.add("clicked");
// }
function changeImage(element) {
if (element.style.color == "red") {
element.style.color = "grey"
}
else {
element.style.color = "red"
}
}
document.addEventListener("DOMContentLoaded", function() {
var emailInput = document.getElementById("Email");
var passwordInput = document.getElementById("password");
var confirmPasswordInput = document.getElementById("confirm_password");
var emailError = document.getElementById("emailError");
var passwordLatinError = document.getElementById("passwordLatinError");
var passwordLengthError = document.getElementById("passwordLengthError");
var confirmPasswordError = document.getElementById("confirmPasswordError");
var submitButton = document.getElementById("submit");
function isEmailValid(email) {
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
}
function isPasswordValid(password) {
// Проверка на длину пароля и наличие только латинских букв
return password.length >= 8 && /^[a-zA-Z0-9]+$/.test(password);
}
function arePasswordsMatching() {
return passwordInput.value === confirmPasswordInput.value;
}
function enableSubmitButton() {
submitButton.disabled = !(isEmailValid(emailInput.value) && isPasswordValid(passwordInput.value) && arePasswordsMatching());
}
function emailEvent() {
if (isEmailValid(emailInput.value)) {
emailError.style.display = "none";
} else {
emailError.style.display = "block";
}
enableSubmitButton();
}
function passwordEvent() {
if (isPasswordValid(passwordInput.value)) {
passwordLatinError.style.display = "none";
passwordLengthError.style.display = "none";
} else {
if (passwordInput.value.length < 8) {
passwordLengthError.style.display = "block";
} else {
passwordLengthError.style.display = "none";
}
if (!/^[a-zA-Z]+$/.test(passwordInput.value)) {
passwordLatinError.style.display = "block";
} else {
passwordLatinError.style.display = "none";
}
}
enableSubmitButton();
}
function confirmPasswordEvent() {
if (arePasswordsMatching()) {
confirmPasswordError.style.display = "none";
} else {
confirmPasswordError.style.display = "block";
}
enableSubmitButton();
}
emailInput.addEventListener("input", emailEvent);
passwordInput.addEventListener("input", passwordEvent);
confirmPasswordInput.addEventListener("input", confirmPasswordEvent);
});