-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregistrationscript.js
More file actions
54 lines (49 loc) · 2.35 KB
/
registrationscript.js
File metadata and controls
54 lines (49 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
changeStatus();
function changeStatus() {
const Registering = document.getElementById('Registering');
const Specialization = document.getElementById('Specialization');
if (Registering.value === 'Doctor') {
Specialization.classList.remove('hidden');
} else {
Specialization.classList.add('hidden');
}
}
const form = document.getElementById('registrationForm');
const phoneInput = document.getElementById('phone');
const passwordInput = document.getElementById('password');
const confirmPasswordInput = document.getElementById('confirmPassword');
form.addEventListener('submit', (event) => {
if (!validatePhoneNumber(phoneInput.value)) {
event.preventDefault();
alert('Invalid phone number. Phone number should be 10 digits and start with 6 or above.');
} else if (passwordInput.value !== confirmPasswordInput.value) {
event.preventDefault();
alert('Passwords do not match.');
} else if (!validatePasswordComplexity(passwordInput.value)) {
event.preventDefault();
alert('Password should be at least 8 characters long and contain at least one uppercase letter and one digit.');
} else {
const scriptURL = 'https://script.google.com/macros/s/AKfycbwQqMgS1oePiBkJG19PigWO0qEK9WHU4qpldHviMo8nNX2xbW__fRe2kJ48uc1Vr2O3KA/exec';
const form = document.forms['google-sheet']
event.preventDefault();
fetch(scriptURL, { method: 'POST', body: new FormData(form)})
.then(response => {
alert("Thanks for Registering with us..!");
// Optionally, you can reset the form after successful submission
form.reset();
// Redirecting to sign in page
window.location.href = 'signin.html';
})
.catch(error => console.error('Error!', error.message));
}
});
function validatePhoneNumber(phone) {
const phonePattern = /^[6-9]\d{9}$/; //Added logic phone no. should start with 6 or above to avoid invalid numbers.
return phonePattern.test(phone);
}
function validatePasswordComplexity(password) {
// Check if the password is at least 8 characters long
// and contains at least one uppercase letter and one digit
const passwordPattern = /^(?=.*[A-Z])(?=.*\d).{8,}$/;
return passwordPattern.test(password);
}