Question: the javascript validation doesn't seem to work when I try to run the webpage I tried to do all in one file and I also

the javascript validation doesn't seem to work when I try to run the webpage I tried to do all in one file and I also tried to put in separate files as file.js and the HTML where I tried to call the file by writing this just the java scirot code function validate(){
var name = document.getElementById("name").value;
var email = document.getElementById("email").value;
var phoneNumber = document.getElementById("phone number").value;
var password = document.getElementById("password").value;
var confirmPassword = document.getElementById("confirm password").value;
var errorMessage = document.getElementById("error_message");
errorMessage.innerHTML ="";
var text;
if (name.length <5){
text = "Please enter a valid name (minimum 5 characters)";
errorMessage.classList.add("error");
errorMessage.innerHTML = text;
return false;
}
if (!validateEmail(email)){
text = "Please enter a valid email address (must contain '@' and be at least 6 characters)";
errorMessage.classList.add("error");
errorMessage.innerHTML = text;
return false;
}
// Enforce Numbers-Only Password (with Security Warning)
if (isNaN(password)){
text = "Password must only contain numbers. **WARNING:** Using only numbers makes your password significantly weaker and easier to crack. Please consider using a mix of numbers, letters, and symbols for better security.";
errorMessage.classList.add("error");
errorMessage.innerHTML = text;
return false;
}
if (confirmPassword !== password){
text = "Passwords do not match. Please re-enter your password.";
errorMessage.classList.add("error");
errorMessage.innerHTML = text;
return false;
}
console.log("Form submitted successfully!");
alert("Form submitted successfully!");
return true;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!