-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
32 lines (26 loc) · 986 Bytes
/
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
function validateForm() {
// Get form elements
let fname = document.getElementById("fname").value;
let lname = document.getElementById('lname').value;
let email = document.getElementById("email").value;
// Validation logic
if (fname === "" || fname === null) {
document.getElementById('fname-alert').innerHTML= " First name is required.";
return false;
}
if (lname === "" || lname === null) {
document.getElementById('lname-alert').innerHTML='Last Name is required.';
return false;
}
if (email === "" || !validateEmail(email)) {
document.getElementById('email-alert').innerHTML="Please enter a valid email address.";
return false;
}
// If all validations pass, return true
return true;
}
function validateEmail(email) {
// Simple email validation using a regular expression
let re = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
return re.test(email);
}