-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
107 lines (94 loc) · 3.15 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
const emailCheck = () =>{
let email = document.getElementsByName('email')[0].value;
let emailMessage = document.getElementsByName('emailmessage')[0];
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) {
emailMessage.style.display = 'none';
return true;
}
else if(email == ""){
emailMessage.innerHTML = "Empty field"
emailMessage.style.display = 'block';
return false;
}
else {
emailMessage.innerHTML = "That's not a valid e-mail"
emailMessage.style.display = 'block';
return false;
}
}
const termsCheck = () =>{
let terms = document.getElementsByName("checkboxG1")[0];
if(terms.checked) return true;
else return false;
}
const reCaptcha = () =>{
let Cap = document.getElementsByName("checkboxG2")[0];
if(Cap.checked) return true;
else return false;
}
const passwordCheck = () => {
let password1 = document.getElementsByName("password1")[0].value;
let passmessage = document.getElementsByName('pass1message')[0];
let message = 'Password is missing:';
let isPasswordGood = true;
if(!(/[a-z]/.test(password1))){
isPasswordGood = false;
message+= " small letter";
}
if(!(/[A-Z]/.test(password1))){
if(!isPasswordGood) message+= ", big letter";
else message+= " big letter";
isPasswordGood = false;
}
if(!(/\d/.test(password1))){
if(!isPasswordGood) message+= ", number";
else message+= " number";
isPasswordGood = false;
}
let format = /[ `!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/;
if(!(format.test(password1))){
if(!isPasswordGood) message+= ", special sign";
else message+= " special sign";
isPasswordGood = false;
}
if(!isPasswordGood){
passmessage.style.display = 'block';
passmessage.innerHTML = message;
return false;
}else{
passmessage.style.display = 'none';
return true;
}
}
const passwordCheckMatch = () => {
let password1 = document.getElementsByName("password1")[0].value;
let password2 = document.getElementsByName("password2")[0].value;
let pasMes = document.getElementsByName("pass2message")[0];
if(password1 == password2) {
pasMes.style.display = 'none';
return true;
}
else {
pasMes.style.display = 'block';
return false;
}
}
const formCheck = () => {
if(passwordCheck() && termsCheck() && reCaptcha() && emailCheck()){
alert("Formularz wyslano")
}
else{
console.log("eh")
}
}
const email = document.getElementsByName('email')[0];
email.addEventListener('input', emailCheck);
const password1 = document.getElementsByName("password1")[0];
password1.addEventListener('input',passwordCheck)
const password2 = document.getElementsByName("password2")[0];
password2.addEventListener('focusout', passwordCheckMatch)
const button = document.getElementsByName('submit')[0];
button.addEventListener('click', function(event){
event.preventDefault();
formCheck();
});