-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
138 lines (107 loc) · 4.88 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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
const form = document.querySelector(".form-section")
const form_btn = document.querySelector(".form-btn")
const confirm_submit_msj = document.querySelector(".confirm-submit-msj")
const input_name = document.querySelector(".form-input-name")
const holder_name = document.querySelector(".cardholder-name")
const input_number = document.querySelector(".form-input-number")
const card_number = document.querySelector(".card-number")
const input_exp_month = document.querySelector(".form-input-month")
const input_exp_year = document.querySelector(".form-input-year")
const input_cvc = document.querySelector(".cvc-code-number")
window.onload = () => {
document.querySelector(".front-card").style.cssText = "animation: appear-cards 600ms linear";
document.querySelector(".back-card").style.cssText = "animation: appear-cards 900ms linear";
form.style.animation = "appear-form 1s linear";
document.querySelector(".attribution").style.animation = "confirm-submit-msj 1.5s forwards";
};
/* send form */
form.addEventListener("submit", (e) => {
e.preventDefault();
form.remove()
document.querySelector(".user_name").innerHTML += input_name.value
confirm_submit_msj.style.cssText = "animation: confirm-submit-msj 600ms linear ;display:flex";
document.querySelector(".check_icon").style.cssText = "animation:check_icon 900ms linear; display:block";
});
/* card holder-name */
input_name.addEventListener("change", (e) => {
let regexp = /^([A-Za-zÑñÁáÉéÍíÓóÚú]+\s)+([A-Za-zÑñÁáÉéÍíÓóÚú]+[A-Za-zÑñÁáÉéÍíÓóÚú]+)$/;
let validar = regexp.test(input_name.value)
if (validar && e.target.value.length > 6) {
holder_name.innerHTML = e.target.value
input_name.classList.add('cheked')
} else {
input_name.value = ""
input_name.insertAdjacentHTML("afterend", `<p class="alert-msj-name">you need to put your full name</p>`)
setTimeout(() => {
document.querySelector(".alert-msj-name").remove()
}, 3000);
}
});
/* card number */
input_number.addEventListener("change", (e) => {
let regexp = /^(([0-9]{4}\s){3}[0-9]{4})$/;
let validar = regexp.test(input_number.value)
if (validar) {
card_number.innerHTML = e.target.value
input_number.classList.add('cheked')
} else {
input_number.value = ""
input_number.insertAdjacentHTML("afterend", `<p class="alert-msj-number">wrong format, only numbers is allowed</p>`)
setTimeout(() => {
document.querySelector(".alert-msj-number").remove()
}, 3000);
}
});
/* expiration date section */
input_exp_month.addEventListener("change", (e) => {
if (isNaN(input_exp_month.value) || (input_exp_month.value > 12 || input_exp_month < 1)) {
input_exp_month.value = ""
input_exp_month.insertAdjacentHTML("afterend",`<div class="info-msj">wrong month, repeat plis</div>`)
setTimeout(() => {
document.querySelector(".info-msj").remove()
}, 2000);
} else {
input_exp_month.classList.add('cheked')
document.querySelector(".exp-month").innerHTML = e.target.value
}
});
input_exp_year.addEventListener("change", (e) => {
if (isNaN(input_exp_year.value) || input_exp_year.value < 2023) {
input_exp_year.value = ""
input_exp_year.insertAdjacentHTML("afterend",`<div class="info-msj" style="transform:translateX(9em)">wrong year, repeat plis</div>`)
setTimeout(() => {
document.querySelector(".info-msj").remove()
}, 2000);
} else {
input_exp_year.classList.add('cheked')
document.querySelector(".exp-year").innerHTML = e.target.value
}
});
input_cvc.addEventListener("change", (e) => {
if (parseInt(e.target.value) && e.target.value.length == 3) {
document.querySelector(".cvc-number").innerHTML = e.target.value
input_cvc.classList.add('cheked')
} else {
input_cvc.value = ""
input_cvc.insertAdjacentHTML("afterend", `<p class="alert-msj-cvc">wrong code! must be the real code</p>`)
setTimeout(() => {
document.querySelector(".alert-msj-cvc").remove()
}, 2000);
}
});
/* confirm boton */
form_btn.addEventListener("click", () => {
const inputs = [input_name, input_number, input_exp_month, input_exp_year, input_cvc];
inputs.forEach((input) => {
if (!input.classList.contains('cheked')) {
input.style.animation = 'wrong 300ms infinite linear';
setTimeout(() => {
input.style.removeProperty('animation')
}, 1500);
}
});
});
document.querySelector(".confirm-submit-btn").addEventListener("click", () => {
alert('Thank you very much for testing the functionality of the form')
location.reload()
});