-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
70 lines (59 loc) · 2.35 KB
/
script.js
File metadata and controls
70 lines (59 loc) · 2.35 KB
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
document.getElementById("userForm").addEventListener("submit", function(event) {
event.preventDefault();
let isValid = true;
// Validation patterns
const namePattern = /^[A-Za-z\s]+$/;
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
const phonePattern = /^\d{10}$/;
// Fields
const fullName = document.getElementById("fullName");
const email = document.getElementById("email");
const phone = document.getElementById("phone");
const gender = document.getElementById("gender");
const city = document.getElementById("city");
const state = document.getElementById("state");
const country = document.getElementById("country");
const address = document.getElementById("address");
const message = document.getElementById("message");
const cv = document.getElementById("cv");
const terms = document.getElementById("terms");
// Error spans
const fullNameError = document.getElementById("fullNameError");
const emailError = document.getElementById("emailError");
const phoneError = document.getElementById("phoneError");
// Validation logic
if (!namePattern.test(fullName.value)) {
fullNameError.classList.remove("hidden");
isValid = false;
} else {
fullNameError.classList.add("hidden");
}
if (!emailPattern.test(email.value)) {
emailError.classList.remove("hidden");
isValid = false;
} else {
emailError.classList.add("hidden");
}
if (!phonePattern.test(phone.value)) {
phoneError.classList.remove("hidden");
isValid = false;
} else {
phoneError.classList.add("hidden");
}
if (!gender.value || !city.value || !state.value || !country.value || !address.value || !message.value) {
alert("All fields are required.");
isValid = false;
}
if (!cv.files[0] || !cv.files[0].name.match(/\.(pdf|doc|docx)$/)) {
alert("Please upload a valid CV in .pdf, .doc, or .docx format.");
isValid = false;
}
if (!terms.checked) {
alert("You must agree to the terms and conditions.");
isValid = false;
}
if (isValid) {
alert("Form submitted successfully!");
document.getElementById("userForm").reset();
}
});