-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascript.js
More file actions
51 lines (40 loc) · 1.6 KB
/
javascript.js
File metadata and controls
51 lines (40 loc) · 1.6 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
async function validateAndSubmit(event) {
event.preventDefault(); // Prevent the default form submission behavior
if (!validateForm()) {
return; // Stop further execution if validation fails
}
const formData = new FormData(document.getElementById('login-form'));
try {
const response = await fetch('/login', {
method: 'POST',
body: formData,
});
if (response.ok) {
console.log('Login successful');
// Optionally redirect or perform other actions upon successful login
// window.location.href = 'https://portals.au.edu.pk/students/';
} else {
console.error('Login failed:', response.status, response.statusText);
// Handle the error, show a message, or perform other actions upon failed login
}
} catch (error) {
console.error('Error during login:', error);
// Handle unexpected errors during login
}
}
function validateForm() {
var password = document.getElementById('password').value;
// Check maximum length
if (password.length < 10) {
alert("Password must be at most 10 characters.");
return false;
}
// Check for at least 2 special characters and 1 number
var specialCharCount = password.replace(/[^!@#$%^&*(),.?":{}|<>]/g, '').length;
var numberCount = password.replace(/[^0-9]/g, '').length;
if (specialCharCount < 2 || numberCount < 1) {
alert("Password must contain at least 2 special characters and 1 number.");
return false;
}
return true;
}