I could not add the JavaScript code for this website. It will be much appreciated if you can help me with this.
Wesley
@Wesleys-hubAll comments
- @ShahinthecoderSubmitted almost 4 years ago@Wesleys-hubPosted almost 4 years ago
Hey man, i would sugget adding an id to the form and the input. Make the styles following the design (active-states) image and add them when the user fills in either a correct or a wrong input
// get the form and input const form = document.getElementById("form"); const email = document.getElementById("email");
// add event listener to button form.addEventListener("submit", (e) => { e.preventDefault(); // get the value of the input const emailVal = email.value;
let validateEmail = () => { let filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/; // if not correct add error class and remove correct class if (!filter.test(emailVal)) { form.classList.add("form-error"); form.classList.remove("form-correct"); // if correct add correct class and remove error class } else { form.classList.remove("form-error"); form.classList.add("form-correct"); } }; validateEmail(); });
2