Script
Script
// Validate Name
if (name.trim() === "") {
isValid = false;
showError('nameError', "Name is required");
}
// Validate Email
const emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
if (!emailPattern.test(email)) {
isValid = false;
showError('emailError', "Please enter a valid email");
}
// Validate Password
const passwordStrengthPattern = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d@$!%*?&]{8,}$/;
if (!passwordStrengthPattern.test(password)) {
isValid = false;
showError('passwordError', "Password must be at least 8 characters long and
contain at least one letter and one number");
}
// If all validations pass, submit the form (or you can do further actions here)
if (isValid) {
alert("Form submitted successfully!");
// Optionally: you can submit the form here using form.submit() or perform
other actions.
}
});