-
Notifications
You must be signed in to change notification settings - Fork 0
/
reservationsapp.js
91 lines (83 loc) · 2.6 KB
/
reservationsapp.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
const navSlide = () => {
const lines = document.querySelector(".lines");
const nav = document.querySelector(".nav-links");
const navLinks = document.querySelectorAll(".nav-links li");
lines.addEventListener("click", () => {
//Toggle Nav
nav.classList.toggle("nav-active");
//Animate Links
navLinks.forEach((link, index) => {
if (link.style.animation) {
link.style.animation = "";
} else {
link.style.animation = `navLinkFade 0.5s ease forwards ${index / 3}s`;
}
});
//Lines animation
lines.classList.toggle("toggle");
});
};
navSlide();
var firstnameError = document.getElementById("firstname-error");
var lastnameError = document.getElementById("lastname-error");
var phonenumberError = document.getElementById("phonenumber-error");
var emailError = document.getElementById("email-error");
var dateError = document.getElementById("date-error");
var btnError = document.getElementById("btn-error");
function validateFirstName() {
var firstname = document.getElementById("first-name").value;
if (firstname.length == 0) {
firstnameError.innerHTML = "First Name Is Required";
return false;
}
firstnameError.innerHTML = '<i class="fa-solid fa-badge-check"></i>';
return true;
}
function validateLastName() {
var lastname = document.getElementById("last-name").value;
if (lastname.length == 0) {
lastnameError.innerHTML = "Last Name Is Required";
return false;
}
lastnameError.innerHTML = "";
return true;
}
function validatePhone() {
var phonenumber = document.getElementById("phone-number").value;
if (phonenumber.length == 0) {
phonenumberError.innerHTML = "Phone Number Is Required";
return false;
}
if (phonenumber.length !== 10 && phonenumber.length !== 11) {
phonenumberError.innerHTML = "Phone Number should be 10 or 11 digits";
return false;
}
phonenumberError.innerHTML = "";
return true;
}
function validateEmail() {
var email = document.getElementById("email-address").value;
if (email.length == 0) {
emailError.innerHTML = "Email Address Is Required";
return false;
}
if (!email.match(/^[A-Za-z\._\-[0-9]*[@][A-Za-z]*[\.][a-z]{2,5}$/)) {
emailError.innerHTML = "Invalid Email";
return false;
}
emailError.innerHTML = "";
return true;
}
function validateForm() {
if (
!validateFirstName() ||
!validateLastName() ||
!validatePhone() ||
!validateEmail()
) {
btnError.innerHTML = "Check Your Details";
return false;
}
btnError.innerHTML = "";
return true;
}