-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
57 lines (43 loc) · 1.41 KB
/
script.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
let login_obj = document.getElementById('login_box')
login_obj.addEventListener('click', validateLoginForm)
function validateEmail(email) {
//regular expression to check if the email is valid
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
return emailRegex.test(email);
}
function validatePassword(password) {
// Customize these rules to match your password requirements
const minLength = 5;
const hasUpperCase = /[A-Z]/.test(password);
const hasLowerCase = /[a-z]/.test(password);
const hasNumber = /\d/.test(password);
return (
password.length >= minLength &&
hasUpperCase &&
hasLowerCase &&
hasNumber
);
}
// validation login
function validateLoginForm(event) {
event.preventDefault();
const email = document.getElementById('email_box');
const password = document.getElementById('password_box');
// Validate email
if (!validateEmail(email.value)) {
alert('Please enter a valid email address.');
return;
}
// Validate password
if (!validatePassword(password.value)) {
alert('Please enter a valid password.');
return;
}
if (email.value === 'Brindha@gmail.com' && password.value === "Brindha") {
alert('Login successful!');
window.location.href = 'home_page/index.html';
}
else {
alert('Give valid Username and Password');
}
}