-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.js
90 lines (77 loc) · 2.92 KB
/
app.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
const firebaseConfig = {
apiKey: "AIzaSyAwk_a5_WqIkeTJwnDMIr0L1nuC8DBni6Y",
authDomain: "buddy-community-7d95b.firebaseapp.com",
databaseURL: "https://buddy-community-7d95b-default-rtdb.firebaseio.com",
projectId: "buddy-community-7d95b",
storageBucket: "buddy-community-7d95b.appspot.com",
messagingSenderId: "135788365725",
appId: "1:135788365725:web:b11542b8e75179e3319174",
measurementId: "G-YGET6LFW6E"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
var contactFormDB = firebase.database().ref('hack-invites');
document.getElementById("contactForm").addEventListener('submit', (e) => {
e.preventDefault();
const emailid = document.getElementById("emailid").value;
const name = document.getElementById("name").value;
const phone = document.getElementById("phone").value;
const regno = document.getElementById("regno").value;
const lang = document.getElementById("Lang").value;
if (!emailid || !name || !phone || !regno || !lang) {
alert("Please fill in all the fields.");
return; // Prevent form submission
}
if (!validateRegistrationNumber(regno)) {
document.getElementById("regnoError").style.visibility = "visible";
return; // Prevent form submission
}else {
document.getElementById("regnoError").style.visibility = "hidden";
}
if (!validatePhoneNumber(phone)) {
// Display error message on the page
document.getElementById("phoneError").style.visibility = "visible";
return; // Prevent form submission
} else {
// Clear the error message if phone number is valid
document.getElementById("phoneError").style.visibility = "hidden";
}
if (!validateEmailAddress(emailid)) {
document.getElementById("emailError").style.visibility = "visible";
return; // Prevent form submission
} else {
document.getElementById("emailError").style.visibility = "hidden";
}
saveMessages(emailid, name, phone, regno, lang);
});
const saveMessages = (emailid, name, phone, regno, lang) => {
var newContactForm = contactFormDB.push();
newContactForm.set({
name: name,
emailid: emailid,
phone: phone,
regno: regno,
lang: lang
})
.then(() => {
window.location.replace("/success.html");
})
.catch((error) => {
window.location.replace("/failure.html");
});
};
function validateRegistrationNumber(regno) {
// Regular expression to match the desired format
const regex = /^\d{2}[A-Za-z]{1,5}\d{4,5}$/;
return regex.test(regno);
}
function validatePhoneNumber(phone) {
// Regular expression to match exactly 10 digits
const regex = /^\d{10}$/;
return regex.test(phone);
}
function validateEmailAddress(email) {
// Regular expression to match the required format
const regex = /^[a-zA-Z0-9._%+-]+@vitstudent\.ac\.in$/;
return regex.test(email);
}